2014-11-03 108 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