You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »


You can close tabs in a browser that are associated with a specific domain like "foo.com" using the following JavaScript code

// Get all open windows in the browser
const windows = window.top;

// Loop through each window
for (let i = 0; i < windows.length; i++) {
  // Get all the tabs in the current window
  const tabs = windows[i].document.getElementsByTagName('a');

  // Loop through each tab
  for (let j = 0; j < tabs.length; j++) {
    // Check if the tab's URL contains "foo.com"
    if (tabs[j].href.includes('google.com')) {
      // Close the tab
      windows[i].close();
    }
  }
}



  • No labels