...
Excerpt |
---|
You can close tabs in a browser that are associated with a specific domain like "foo.com" using the following JavaScript code |
Code Block |
---|
// Get all open windows in the browser const windows = window.top; // Loop through each window for (let i = 0; i < windows.length; i++) { // Getfunction close_tabs(domain_name) { // get all the tabs in the current window const tabsopen windows var windows = windows[i].document.getElementsByTagName('awindow.open('', '_blank'); // Looploop through eachall tab the open windows for (letvar ji = 0; ji < tabswindows.length; ji++) { // Checkcheck if the tabwindow's URL contains "foo.com" includes domain_name if (tabswindows[ji].location.href.includes('google.com')) { // Close the tab indexOf(domain_name) > -1) { // close the window windows[i].close(); } } } close_tabs( "foo.com"); |