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

Compare with Current View Page History

« Previous Version 2 Current »


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

function close_tabs(domain_name)
{
	// 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 domain_name
			if (tabs[j].href.includes(domain_name)) {
				// Close the tab
    			windows[i].close();
			}
		}
	}
}
close_tabs("foo.com");




  • No labels