简体   繁体   中英

javascript close window for external url

In my page when I click on a link a popup will be opened. In that popup, I have the close button. To close the window I am using simple javascript function as window.close() . This is working fine.

Now when I copy the url of the popup link and open it in new window, I am not able to close the window.

In Firefox when using firebug the warning given is, 'Scripts may not close windows that were not opened by script.'

Please help me out on any other alternative.

Thanks in advance.

Firefox seems to answer that question: 'Scripts may not close windows that were not opened by script.'

This is a security measure. Imagine every site could close every other page you have open, that wouldn't work very well would it? That's why only a parent window may close its children windows.

There may be a setting Firefox that allows windows not opened by script to be closed by script, but even if there is, what chance is there that your visitors will all have enabled this setting?

You can't work around this problem, it is how Firefox (and certainly other browsers) works. The only answer is to change your approach.

Why are you using windows as popups anyway? This has not been recommended for some time now and is mostly frowned upon. Popups that are actual windows may be blocked by popup-blockers.

You should probably use a modal popup instead of a window

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM