Safari extension: execute bookmarklet-url
Hey there,
I am new to Safari development and would be happy if you can help me.
I try to build a extension of a bookmarklet-url (OneNote) so I would be able to have a button in Safari – and not only a bookmark in favorites bar. But I am too silly to understand how to execute this bookmarklet-url in javascript. I tried currentTab.url but it does not work. If I click on the new shiny button nothing happens.
Which code I have to use, that the bookmarklet-url is executed – just as the link in the favorites bar works.
Link in the favorites bar:
javascript:(function(){var%20jsCode=document.createElement('script');jsCode.setAttribute('src','https://www.onenote.com/Clipper/Root?ClipperId=ON-45519f6d-f536-4649-8856-5e4157dffe10&ClipperType=Bookmarklet&ClipperVersion=2.0.2');jsCode.setAttribute('id','oneNoteCaptureRootScript');jsCode.setAttribute('type','text/javascript');document.body.appendChild(jsCode);})()
global.html
<!DOCTYPE html>
<html>
<head>
<title>Microsoft OneNote Clipper</title>
<script type="text/javascript" charset="utf-8">
// register with application
safari.application.addEventListener("command", performCommand, false);
function performCommand(event) {
if (event.command === "clip-onenote") {
// Run OneNote Clipper
(function(){
var jsCode = document.createElement('script');
jsCode.setAttribute('src','https://www.onenote.com/Clipper/Root?ClipperId=ON-45519f6d-f536-4649-8856-5e4157dffe10&ClipperType=Bookmarklet&ClipperVersion=2.0.2');
jsCode.setAttribute('id','oneNoteCaptureRootScript');
jsCode.setAttribute('type','text/javascript');
document.body.appendChild(jsCode);
})()
}
}
</script>
</head>
<body>
</body>
</html>
Thank you very much for your help! 🙂
MacBook Air (13-inch Mid 2012), OS X Yosemite (10.10.3), Safari