JS closes the current page/closes the current window (compatible with all browsers)

Source: Internet
Author: User

Windows Self-band method

Window.close ()

The code is as follows Copy Code

<a href= "Javascript:self.close ()" > Close window </a>

This approach is a lot of problems, incompatible is not more introduced, the following we look at an example

Window.close () is OK, but it will give you a hint. The page you are viewing is attempting to close the window. Do you want to close the window? "How can you not eject this hint?"
"If you open this page for the first time, Window.close () will pop-up prompts, if this page is by other pages window.open () out of the page, Window.close (), there will be no prompts

window does not prompt for automatic shutdown of JS code

The code is as follows Copy Code


Normal with tips off
function Closeie () {
Window.close ();
}
Close IE6 do not prompt
function Closeie6 () {
Window.opener=null;
Window.close ();
}
Close IE7 do not prompt
function Closeie7 () {
window.open (', ' _top ');
Window.top.close ();
}

But all in

FF is not used up, and later found a good compatible with all browsers to close the current page function

  code is as follows copy code

function Closewebpage () {
 if (navigator.userAgent.indexOf ("MSIE") > 0) {
  if (navigator.userAgent.indexOf ("MSIE 6.0") > 0) {
   window.opener = nul L
   window.close ();
  } else {
   window.open (', ' _top ');
   window.top.close ();
&NBSP;&NBSP}
 }
 else if (navigator.userAgent.indexOf ("Firefox") > 0) {
   window.location.href = ' About:blank ';
 } else {
  window.opener = null;
  window.open (', ' _self ', ');
   Window.close ();
 }
}

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.