admin管理员组文章数量:1429613
I'd like to provide a button on my child page that would close the child page from the child page itself. To make matters worse, I didn't write the child page - it is written using frames. So far I've tried this code in the child page:
Window.opener.location= '/parent page.html';
Window.close();
And, in the body:
<a href="JavaScript:if(confirm('close window?')) window.close()">close</a>
HELP!
I'd like to provide a button on my child page that would close the child page from the child page itself. To make matters worse, I didn't write the child page - it is written using frames. So far I've tried this code in the child page:
Window.opener.location= '/parent page.html';
Window.close();
And, in the body:
<a href="JavaScript:if(confirm('close window?')) window.close()">close</a>
HELP!
Share Improve this question edited Aug 19, 2012 at 9:21 Lee Taylor 7,99416 gold badges37 silver badges53 bronze badges asked Aug 19, 2012 at 5:16 user1609616user1609616 231 silver badge3 bronze badges 2- If it helps, the child page was created by google picasa. I'm able to get the word "close" to appear on the page, and the pop up window appears to confirm if I want to close the window, but nothing happens when I click "yes" – user1609616 Commented Aug 19, 2012 at 5:58
- 1 You can close only those pages that were opened via Javascript. – Nivas Commented Aug 19, 2012 at 6:41
2 Answers
Reset to default 5As the link you inserted is inside an iframe, use window.top.close()
instead of window.close()
. window.top
will refer to child window you created.
HTML for your hyperlink will be
<a href="javascript: if(confirm('close window')) {window.top.opener.location ='/auctioneer notes 8_22_12.html';window.top.close();}">close window</a>
This is cheating, but by refreshing the parent window the child window gets closed. Not very elegant but it works.
<form METHOD=post><p align=right><input TYPE="button" VALUE="Close This Window"onClick="window.parent.location.reload();"></p></form>
本文标签: javascriptHow can I close a child windowStack Overflow
版权声明:本文标题:javascript - How can I close a child window? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745486609a2660412.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论