Safari Extension Current Page URL

Discussion in 'Mac Programming' started by Vitaminwater, Jul 28, 2010.

  1. Vitaminwater macrumors newbie

    Aug 18, 2009

    Being interested in the new safari extension's i'm trying to write my own little tool to help productivity. All i'm trying to do is get the current page URL and having a heck of a time.

    THe plugin is running just fine but not outputting the right information. Here the plugin code:
    <!DOCTYPE html>
    	<title>Hello World</title>
    	<script type="text/javascript" charset="utf-8">
    function performCommand(event)
        if (event.command === "sayHello") {
    // if event handlers are in the global HTML page,
    // register with application:
    safari.application.addEventListener("command", performCommand, true);
    safari.application.addEventListener("validate", validateCommand, true);
    The code seems to be outputting the URL of the plugin.

    ANy idea? Thanks
  2. kainjow Moderator emeritus


    Jun 15, 2000
  3. Vitaminwater thread starter macrumors newbie

    Aug 18, 2009
    kainjow, that worked great, thank you very much for the quick response and the useful doc link.

    However, i'm now trying to open a new tab with safari to a specified url, i've gotten it to open the tab, but not sure how to target a URL. From the readings you gave me i see that:
    THis must be what i have to do but not sure how to work this.
    var myurl = safari.application.activeBrowserWindow.activeTab.url;
    var newTab = safari.application.openBrowserWindow().activeTab;
    Thanks Again!

Share This Page