简体   繁体   中英

close all browser tabs except current tab via javascript

I want to close all active tab except the current tab. Is this possible?

In my web site, when a user uses many tabs in same browser it fails. I want to close all tabs except the current one when any events triggered.

Here is a solution that I found:

function close_window() {
    if (confirm("Close Window?")) {
      close();
    }
}

This will work but how can I access other tabs?

You can't directly control other tabs. You could instead pass them information by writing to cookies or local storage and having all tabs monitor that space.

However, I think that if your site doesn't work when open in multiple tabs, you should be focusing on fixing that problem.

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