Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Bookmarklet IE8

Tags:

javascript

Has anyone an idea why the following JavaScript codes is working without any problems on Firefox and was working on IE7 as well but not on IE8 anymore? I have not a clue and I appreciate any hint :-)

I have added the code as a favorite item to my Internet Explorer. So a click on this favorite item should execute the code and load a JavaScript file which is located on my server and append it to the website which is currently loaded in the browser.

javascript:void((
function(){
    var%20e=document.createElement('script');
    e.setAttribute('type','text/javascript');
    e.setAttribute('src','http://www.mydomain.com/js/bookmarklet.js');
    document.body.appendChild(e)
}
)())

Thanks for any help and happy coding :-)

like image 809
chris Avatar asked May 23 '26 12:05

chris


1 Answers

The correct way to add a script to a web page would be:

var scriptNode = document.createElement('script');
scriptNode.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(scriptNode);

Please, try that, it works in IE8.

like image 116
Boris Hamanov Avatar answered May 26 '26 02:05

Boris Hamanov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!