开发者

Javascript Bookmarklet IE8

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 :-)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜