JavaScript (JS) with window.close () control the closing invalid when Chrome (Google) browser the current page solution

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/IT_ZZQ/article/details/102743829

Encountered in the development of such a situation:

Chrome (Google) browser, after performing certain operations need to close the current page directly, but using window.close (); invalid, can not close the current page.

Check that:

In Chrome, you must specify the window.location.href = "about: blank"; then call window.close (); method to close the current page properly.

 

How to determine browser type?

navigator.appName BrowserName = var;
IF (BrowserName == "Netscape") {
    window.location.href = "the About: blank"; // Chrome browser must have the words to properly close the page
} else if (browserName = = "in the Microsoft Internet Explorer") {
    window.opener = null;
}
window.close (); // Close

 

Thanks for reading, if any errors or deficiencies, please criticism

Guess you like

Origin blog.csdn.net/IT_ZZQ/article/details/102743829