簡體   English   中英

'javascript:close()'似乎不起作用

[英]'javascript:close()' doesn't seem to be working

我真的是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>

如果尚未通過JavaScript打開窗口,則無法使用close()關閉窗口

嘗試window.close()

document.write("<a href='javascript:window.close()'>Close this window</a>");

沒有名為close函數。 javascript:close(); 只需將函數close調用即可。 如果要關閉彈出窗口,則需要在其上調用close。 像: javascript:actorWin.close();

在這種情況下,請確保在全局范圍內聲明actorWin (將var actorWin;放到function openActor...正上方)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM