2012-10-26 2 views
0

저는 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> 
+1

내가 document.write를 사용하지 않는 게 좋을 것 자바 스크립트를 통해 개설되지 않은 수 없을 때. –

+1

@Lee Taylor : 문서가 이미 닫혀있을 때만 문서의 내용을 덮어 씁니다.이 경우 아직 열려 있으므로 쓰기를 사용할 때 아무런 문제가 없습니다. –

답변

0

을보십시오. javascript:close();은 단순히 close 함수를 호출합니다. 팝업 창을 닫으려면 닫기를 호출해야합니다. 처럼 :이 경우 javascript:actorWin.close();

, 당신은 전역 (단지 function openActor...var actorWin;를 넣어)에 actorWin를 선언해야합니다. 이 페이지에서 무엇을 덮어 쓰기 때문에

0

close라는 이름의 기능이 없습니다 window.close()

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

당신은 close()를 사용하여 차창는 그들은,

관련 문제