safari extension to obtain url from address bar

北城以北 提交于 2019-12-13 05:25:52

问题


I am working on a Safari Extension to obtain the url from the address bar and then send it to a mysql database. This in turn is picked by a website that displays the database content.

The part where I am stuck at is how do I obtain the URL from the address bar from within a Safari Extension ? I am using php to then update the database with the url once I get it. Thanks in advance.


回答1:


This solved my issue.

var myurl = safari.application.activeBrowserWindow.activeTab.url;



回答2:


with javascript

window.location.href



回答3:


From an extension's global page or a popover, the url property of a tab object is the closest you can get to the contents of the tab's address bar. For example,

safari.application.activeBrowser.activeTab.url

It's not exactly what you want because it doesn't reflect a value that may have been typed into the address bar but not yet entered.

If you want to intercept the entered URL before Safari navigates to it, you can listen for the beforeNavigate event on the tab, window, or application. See the documentation.



来源:https://stackoverflow.com/questions/14822404/safari-extension-to-obtain-url-from-address-bar

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