Home  >  Article  >  Web Front-end  >  How to close this window without popping up a question box using javascript_javascript skills

How to close this window without popping up a question box using javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:36:291287browse

Everyone knows that window.close() is used to close the window, and is supported by both IE and Firefox.

In order to achieve the user's absolute control over the browser, when using close to close a non-open window in IE, a dialog box will pop up asking the user how to remove this box. Please see the code below.

function winClose(){ window.top.opener = null; window.close(); }

Just add window.top.opener = null before window.close.

Some people say that firefox does not support close. In fact, this is wrong. The reason why window.close cannot be used in firefox is because firefox cannot close the web page opened by the user by default. You can set firefox like this.

Open firefox and enter about:config in the address bar
Find dom.allow_scripts_to_close_windows and change it to true.
What needs to be said is that there is no trouble with pop-up dialog boxes in Firefox.

<script>
function a(){
window.open('','_parent','');
window.opener = window;
window.close(); 
}
</script>

Run this again and it will be closed under ff.

Seeing this, if the customer is asked to set it up, it means that this function is not implemented, so the result is not very satisfactory. I don’t know if there are any other good alternatives.

Postscript: You can close the current page by opening a new window and then closing this page. Thank you strangebank. But the strange thing is that yesterday I tried it with ff2 without success, but today I tried it with 3 successfully. What a hell, I tried using 2 on my colleague’s machine today and it worked again. But it’s still good to solve the problem early. ^_^

index.html

<a href="c.html" target="_blank">ddddddddd</a>

c.html

<a href="javascript:window.open('','_parent','');window.close();">Close Window</a>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn