스크립트에 랜덤 처리 후 랜덤값에 따라 iframe 호출하려는데~~ 초보라서
본문
자바 스크립트에서 아래와 같이 랜덤값에 따라 alert 하는것은 확인했구요
Alert 대신 iframe으로 호출하려는데,,,에러나는데
A CASE <iframe src="http://aaa.kr/01.html" width=175 height=50 frameborder=0 /></iframe>
B CASE <iframe src="http://aaa.kr/02.html" width=175 height=50 frameborder=0 /></iframe>
C CASE <iframe src="http://aaa.kr/03.html" width=175 height=50 frameborder=0 /></iframe>
<html>
<head> </head>
<body>
<script>
var sec = Math.floor(Math.random() * 10000 + 10000) ;
setTimeout("document.location.reload()", sec);
if (sec > 30000 ){
alert("A CASE" + sec);
} else if ( sec > 20000) {
alert("B CASE" + sec);
} else if ( sec > 10000) {
alert("C CASE" + sec);
} else {
alert("D CASE" + sec);
}
</script>
</body>
</html>
답변 1
올려주신 랜덤 alert 소스를 랜덤 document.write 소스로 변경 해주시면 됩니다.
아래와 같이 해주세요.
<html>
<head> </head>
<body>
<script>
var sec = Math.floor(Math.random() * 40000 + 10000) ;
setTimeout("document.location.reload()", sec);
if (sec > 30000 ){
document.write("A CASE" + sec + "<iframe src='http://aaa.kr/01.html' width=175 height=50 frameborder=0 /></iframe>");
} else if ( sec > 20000) {
document.write("B CASE" + sec + "<iframe src='http://aaa.kr/02.html' width=175 height=50 frameborder=0 /></iframe>");
} else if ( sec > 10000) {
document.write("C CASE" + sec + "<iframe src='http://aaa.kr/03.html' width=175 height=50 frameborder=0 /></iframe>");
} else {
document.write("D CASE" + sec + "<iframe src='http://aaa.kr/04.html' width=175 height=50 frameborder=0 /></iframe>");
}
</script>
</body>
</html>