Banty Roy
Banty Roy

Reputation: 967

Bookmarklet not working/opening in IE10

I created a bookmarklet (tiny javascript function) that works well in ie7,8,9 and Firefox, Chrome, safari but its not working in IE10. Actually not opening in the IE10 when user clicks on the bookmarklet button on the bookmarks bar.

<a href="javascript:(function(){var jsScript=document.createElement('script');
jsScript.setAttribute('type','text/javascript');
jsScript.setAttribute('src', '<?php echo base_url()?>bookmarklet');
document.getElementsByTagName('head')[0].appendChild(jsScript);
var jq=document.createElement('script');jq.setAttribute('type','text/javascript');jq.setAttribute('src', '<?php echo base_url()?>js/jquery/jquery-1.8.3.js');

document.getElementsByTagName('head')[0].appendChild(jq);})();"
title="bookmarklet" 
alt="bookmarklet" 
name="bookmarklet" 
class="bookmarklet_bt_dragable" 
style="cursor:move;">bookmarklet</a> 

The bookmarklet button, by clicking which bookmarklet has to open.

Please someone suggest me how to handle this problem.

Thanks.

Upvotes: 2

Views: 944

Answers (1)

Banty Roy
Banty Roy

Reputation: 967

In the code snippet I use

document.getElementsByTagName('head')[0]

to create head object to append my javaScript file to it.

IE10 treat thia unrated due to this line and as a result discard the javascript code at the time of bookmarklet adding.

Please use

document.getElementsByTagName('head').item(0)

instead of

document.getElementsByTagName('head')[0]

this line and it will work well if any one face this problem.

Upvotes: 1

Related Questions