简体   繁体   中英

How can I open a tab next to the activeTab from a Safari extension?

I want to open a tab using the tabs and windows API, like so...

var newTab = safari.application.activeBrowserWindow.openTab();
newTab.url = blahURL;

...such that the new tab appears next to the currently visible tab. There is a method to do this, but it requires an index. There does not seem to be a way to get the current tab's index. Will I just have to loop through and find the index value of the active tab?

I want to be sure this opens a new tab instead of a window. If I use some JavaScript method to open a new tab, it may open a new window based on user settings, correct?

To get the index of the active tab, you can use

safari.application.activeBrowserWindow.tabs.indexOf(safari.application.activeBrowserWindow.activeTab)

If you use the openTab method of the Safari browser window object, it's guaranteed to open a tab and not a window.

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