java判断safari,/如何使用java脚本在safari浏览器中获取活动的Tab url

How to get the browser window or active tab url using java script in a safari browser ?

I tried to do it using ->

document.url

window.location.href

But both this solutions are giving me so many urls . I dont know why ?

Also I have searched that safari.application.browserWindow.activeTab gives obj of current active window . But I dont know which methods are provided by activeTab class

If anyone knows , plz help me . Thanks in advance.

解决方案

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.

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

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值