IE, Firefox does not prompt to close the window

Source: Internet
Author: User

1, window. Opener = NULL;
Window. Open ("", "_ Self ");
Window. Close ();

2, window. Open ('', '_ parent ','');
Window. Close ();

All of the above are compatible with IE and Firefox.
However, in firefox3, you must enable or disable the window using scripts.

Solution:

Enter about: config in the address bar of Firefox,
Set Dom. allow_scripts_to_close_windows to true to enable the script to close the window.
After all, it is user behavior.

Refer:
---------------------------------------------------------------------

Close the window with JavaScript. You can use the following simple code:

<A href = "javascript: Self. Close ()"> close the window </a>

I passed the test in IE7, but firefox3.0 does not.
Does Firefox not support writing JavaScript directly in href? Then it is changed to the following:

<A href = "javascript: Alert ('Hello World')"> dialog box </a>

Both IE7 and Firefox passed the test. That's not why Javascript is directly written in href.
Continue to test how Firefox closes its window

Changed to the following code:

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en"

Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<SCRIPT type = "text/JavaScript">
<! --
Function windowclose (){
// Self. Close ();
Window. Close ();
}
// -->
</SCRIPT>
<Title> JS test </title>
</Head>
<A href = "javascript: Self. Close ()"> close the window </a> <br/>
<A href = "javascript: Alert ('Hello World')"> dialog box </a> <br/>

<A href = "#" onclick = "windowclose ()"> close the JS function window </a>
<Body>
</Body>
</Html>

You still cannot close the window. Does Firefox not support the close attribute of window?
Can the close method of the window object close the window opened by the open method?

Write the following two HTML files and place them in the same folder.

1.open.html

<SCRIPT type = "text/JavaScript">
<! --
Function OpenWindow (){
Window. Open ("new.html", "newwindow", "width = 200, Height = 100, toolbar = No ");
}
// -->
</SCRIPT>
<A href = "#" onclick = "OpenWindow ()"> open a new window </a> <br/>
<A href = "new.html" target = "_ blank"> hyperlink opens a new page in a new window </a> <br/>
<A href = "new.html" target = "_ parent"> the hyperlink opens a new page in the parent window. </a>

2.new.html

<A href = "javascript: window. Close ()"> close the window </a>
<A href = "javascript: Self. Close ()"> close the window </a>

You can use the open method and open in "_ blank" to close it in a new window, but the open in "_ parent" is still disabled in Firefox.

Now

Therefore, when using the close method of window in Firefox, you should note that it is different from IE: The page opened in the parent window cannot be closed.

Method.

Then I went to Google to search for it. The reason why window. Close is not available in Firefox is that Firefox cannot close users by default.

You can set Firefox as follows:

Open Firefox and enter about: config in the address bar.

Find Dom. allow_scripts_to_close_windows and change it to true.

Now you know why. The article has a good article, which is excerpted as follows:

As we all know, in Javascript, window. Close () is used to close the window, and both IE and Firefox support it. To achieve

Users have absolute control over the browser. When close is used in IE to close a non-open window, a dialog box is displayed asking users. Sometimes I

We don't want to do this again, but how can we remove this box and use the following code?

<Script language = "JavaScript" type = "text/JavaScript">

Function closewindow (){

Window. Open ('', '_ parent ','');

Window. Close ();

}

</SCRIPT>
<A href = "javascript: closewindow ();"> Close Window </a>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.