cocoacoder
cocoacoder

Reputation: 391

safari extension to obtain url from address bar

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.

Upvotes: 0

Views: 402

Answers (3)

cocoacoder
cocoacoder

Reputation: 391

This solved my issue.

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

Upvotes: 1

chulster
chulster

Reputation: 2829

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.

Upvotes: 0

lindosekai
lindosekai

Reputation: 184

with javascript

window.location.href

Upvotes: 0

Related Questions