Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Vitaminwater

macrumors newbie
Original poster
Aug 18, 2009
21
0
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
 

Vitaminwater

macrumors newbie
Original poster
Aug 18, 2009
21
0
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:
The SafariBrowserTab class allows you to identify a tab’s parent browser window, get and set the URL associated with a tab, make a tab active, close a tab, and extract a data:// URL containing a snapshot image of what is rendered in the tab as a base-64 encoded PNG.

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!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.