Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 15, 2013, 03:52 AM   #1
hollerz
macrumors 6502a
 
hollerz's Avatar
 
Join Date: Sep 2006
Location: Durham, UK
Safari Extension - "Safari can't use javascript for this action"

Hi,

I don't know much about coding, so sorry if this is something stupid!

I currently have a Pinterest bookmarklet in my bookmarks bar which runs this code when clicked:

Code:
javascript:void((function(d)%7Bvar%20e=d.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','//assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);d.body.appendChild(e)%7D)(document));

I want to move it to the toolbar, so I have made an extension with the code:

Code:
<!DOCTYPE html>
<html>
<head>
	<title>Pin It!</title>
	<script type="text/javascript" charset="utf-8">



function performCommand(event)
{
    if (event.command === "pinit") {

    var rUrl = "javascript:void((function(d)%7Bvar%20e=d.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','//assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);d.body.appendChild(e)%7D)(document));";
    safari.application.activeBrowserWindow.activeTab.url = rUrl;       
 }
}


safari.application.addEventListener("command", performCommand, true);

</script>
</head>
<body>
</body>
</html>

The bookmarklet works fine when clicked, but the extension gives the error "Safari can't use javascript for this action". Anyone know what's wrong?
hollerz is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 07:37 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC