I'm trying to make an extension that closes all tabs but the active tab for the current window in Safari. I have gotten this far as to close all tabs but index 1. But I need to insert the activetab index and exclude that from the closings. If I get the answer I'd put it in the extension and publish it.
<!DOCTYPE HTML>
<script>
safari.application.addEventListener("command", performCommand, false);
safari.application.addEventListener("validate", validateCommand, false);
function performCommand(event)
{
if (event.command !== "closer")
return;
var tabss = safari.application.activeBrowserWindow.tabs;
for (j=1; j<tabss.length; j++) {
event.target.browserWindow.activeTab.close();
}
}
</script>
What you need to do is iterate through all the tabs in the window closing those which aren't the active tab, for example:
Pseudo-code: Not a copy and paste example...
for (var i = 0; i < tabs.length; i++)
{
if (tab[i] !=== activeTab)
{
tab[i].close();
}
}
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.