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

Similar Threads
thread Thread Starter Forum Replies Last Post
Any way to make it so the "back" and "forward" buttons in a Safari never disappear? TH55 iOS 7 71 Sep 11, 2014 08:23 PM
Make Safari "homepage" a random site among a list I create? jason.siegel Mac Applications and Mac App Store 0 Jan 14, 2014 10:51 AM
Safari will not cut the blank edge under Mavericks("+" button issue) muouyiyi OS X Mavericks (10.9) 1 Oct 9, 2013 02:54 PM
Safari extension: "All Pages Zoom" broken? curtisinoc OS X 10.8 Mountain Lion 6 Aug 9, 2012 10:03 PM
Safari problem - "Safari canít save the file" GeorgeTheBest Web Design and Development 0 Jun 14, 2012 03:37 AM

Forum Jump

All times are GMT -5. The time now is 09:17 AM.

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

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