简体   繁体   English

如何从Safari扩展程序中打开activeTab旁边的标签?

[英]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... 我想使用标签和Windows API打开标签,就像这样...

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? 如果我使用某种JavaScript方法打开新标签页,则可能会根据用户设置打开新窗口,对吗?

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. 如果您使用Safari浏览器窗口对象的openTab方法,则可以确保打开选项卡而不是窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM