/How to get active Tab url in safari browser using java script

浪尽此生 提交于 2019-12-06 04:26:25

If you just want the URL of the "top" document in the current tab, you can use

safari.application.activeBrowserWindow.activeTab.url

from within your extension's global page.

The properties and methods of the SafariBrowserTab class are given here: https://developer.apple.com/library/safari/#documentation/UserExperience/Reference/SBrowserTabClassReference/SafariBrowserTab.html#//apple_ref/doc/uid/TP40009793

I infer from your question that your extension is using an injected script, which is reporting the URL of the page in which it is being run to the global page. Your global page is receiving multiple URLs because the injected script is running not only in the "top" document of the tab, but also in every iframed document inside it.

If you want to prevent the injected script from running inside iframes, wrap the code in a statement like this:

if (window == window.top) {
    // do stuff
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!