2014-11-03 143 views
0

我得到了我的網頁與JS開,與自退出按鈕

<a href="javascript:openNewWindow();"> 

現在,網頁會在_self打開。我需要找到一種方法來獲得鏈接,這將關閉我的窗口。這不工作:

<a href="javascript:window.close();"> 

現在該怎麼辦?任何人都知道更好的方法來關閉自我窗口?第二個腳本已將置於打開的頁面中。

+5

根據[文檔](https://developer.mozilla.org/en-US/docs/Web/API/Window.close),'window.close()'應該可以正常工作。如果不是,你必須提供更多的信息。一個完整的例子會很有用。 – 2014-11-03 14:41:12

回答

-2

這是我以前的答案的修正:

newwindow=window.open(); 
newdocument=newwindow.document; 
newdocument.write("Hello World.<input type='button' value='close' onclick='window.close()' />"); 
newdocument.close(); 

,你可以看到,window.close()的作品確定。如果你能 1. windowOpener.html

<html> 
<body> 
    <input type="button" value="open" onclick="window.open('newWindow.html')" /> 
</body> 
</html> 

2. newWindow.html

<html> 
<body> 
    <input type="button" value="close" onclick="window.close()" /> 
</body> 
</html> 

: -

對於一個具體的例子,你可以使用這個>創建2個文件運行windowOpener.html並點擊'打開'它會打開'newWindow.html'。點擊新打開的窗口中的'關閉',將關閉它。瞧。

+0

「第二個腳本必須位於打開的頁面中。」 – MarioDS 2014-11-03 14:43:03

+0

對不起,但它與我所做的一樣。它不幫助我。 – 2014-11-03 14:45:07

+0

檢查我的新答案。 – Avisho 2014-11-03 14:50:57