Safari Extension Current Page URL

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

  1. Vitaminwater macrumors newbie

    Joined:
    Aug 18, 2009
    #1
    Hello,

    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:
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    	<title>Hello World</title>
    	<script type="text/javascript" charset="utf-8">
    
    
    
    function performCommand(event)
    {
        if (event.command === "sayHello") {
    
    alert(location.href);
           
     }
    }
    
    // if event handlers are in the global HTML page,
    // register with application:
    safari.application.addEventListener("command", performCommand, true);
    safari.application.addEventListener("validate", validateCommand, true);
    </script>
    </head>
    <body>
    </body>
    </html>
    
    The code seems to be outputting the URL of the plugin.

    ANy idea? Thanks
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
  3. Vitaminwater thread starter macrumors newbie

    Joined:
    Aug 18, 2009
    #3
    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.
    Code:
    var myurl = safari.application.activeBrowserWindow.activeTab.url;
    var newTab = safari.application.openBrowserWindow().activeTab;
    
    Thanks Again!
     

Share This Page