0

私はJavaScriptを初めて使用しますが、これはかなり単純なはずだと思います。document.write( "Close this window");を使用して、ウィンドウを閉じるためのリンクを作成しようとしています。

ただし、上記のコードで作成されたリンクをクリックしても何も起こりません。私は何が間違っているのですか?私のコード全体は以下のとおりです。

<!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>
4

3 に答える 3

1

close()javascriptで開かれていないウィンドウを使用してウィンドウを閉じることはできません

于 2012-10-26T00:39:06.417 に答える
0

試すwindow.close()

document.write("<a href='javascript:window.close()'>Close this window</a>");
于 2012-10-26T00:18:37.450 に答える
0

という名前の関数はありませんclosejavascript:close();関数を呼び出すだけですclose。ポップアップウィンドウを閉じたい場合は、その上でcloseを呼び出す必要があります。好き:javascript:actorWin.close();

その場合は、必ずactorWinグローバルスコープで宣言してください(var actorWin;すぐ上に配置function openActor...)。

于 2012-10-26T00:18:39.370 に答える