0

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.

cocoacoder
  • 381
  • 8
  • 19

3 Answers3

1

This solved my issue.

var myurl = safari.application.activeBrowserWindow.activeTab.url;
cocoacoder
  • 381
  • 8
  • 19
  • Hi cocoacoder, I have a related issue to yours, but mine is mainly that I am clueless how to communicate between the global page, the injected script and my extensionbar. Would you mind taking a look at my question? https://stackoverflow.com/questions/53976304/copy-window-location-href-to-clipboard-from-extension – Joe Berg Dec 30 '18 at 14:01
0

with javascript

window.location.href
lindosekai
  • 174
  • 8
  • I tried this "var myWin = window.location.href; alert(window.location.href); safari.application.openBrowserWindow().activeTab.url = window.location.href; " And it doesn't open the url in the new window.I am new to Javascript and web programming in general so sorry if this is a basic question. Thanks again. (Sorry about the comment formatting). – cocoacoder Feb 13 '13 at 23:11
0

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.

chulster
  • 2,809
  • 15
  • 14