저는 JavaScript에 익숙하지 않지만 매우 간단해야한다고 생각합니다. 난 그냥 내 창을 닫으려면 링크를 만들려고 해요 : document.write ("Close this window");'javascript : close()'가 작동하지 않는 것 같습니다.
그러나 위의 코드로 만든 링크를 클릭해도 아무런 변화가 없습니다. 내가 도대체 뭘 잘못하고있는 겁니까? 내 전체 코드는 다음과 같습니다 :
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Loops demo</title>
</head>
<body>
<script type="text/javascript">
function openActor() {
actorWin = window.open("","actorWin","height=200,width=600,resizable");
actorWin.document.write("<!doctype html>");
actorWin.document.write("<html lang=\"en\">");
actorWin.document.write("<head>");
actorWin.document.write("<meta charset=\"utf-8\">");
actorWin.document.write("<title>Keira Knightley</title>");;
actorWin.document.write("</head>");
actorWin.document.write("<body>");
actorWin.document.write("Info on, one of the great actors of our time.");
actorWin.document.write("</body>");
actorWin.document.write("</html>");
}
function Movie(title, actor, web1, web2) {
this.title = title;
this.actor = actor;
this.link = web1;
this.link2 = web2;
}
var movie1 = new Movie('Pride and Prejudice', 'Keira Knightley', 'http://movies.yahoo.com/movie/pride-and- prejudice-2005/','http://keiraknightleyfan.com/');
document.write(movie1.title + '<blockquote>“A lady\'s imagination is very rapid; it jumps from admiration to love, from love to matrimony in a moment.” ― Jane Austen, Pride and Prejudice</blockquote>');
document.write('<a href="javascript:var movieWin = window.open(\'',movie1.link, ' \' ,\'movieWin\',\'height=500,width=500,resizable,top=200,left=400\')">Read more about Pride Prejudice</a><br>');
document.write("<a href='javascript:openActor()'>Click here for info on the lead actor</a><br>");
document.write("<a href='javascript:close()'>Close this window</a>");
</script>
</body>
</html>
내가 document.write를 사용하지 않는 게 좋을 것 자바 스크립트를 통해 개설되지 않은 수 없을 때. –
@Lee Taylor : 문서가 이미 닫혀있을 때만 문서의 내용을 덮어 씁니다.이 경우 아직 열려 있으므로 쓰기를 사용할 때 아무런 문제가 없습니다. –