IE Bug for href=”javascript:

So, if you are a developer like I am, and use very forward thinking code to trigger fun actions like drop-downs and script based navigation you’ve used the href=”javascript:function ” setup before.

Well that doesn’t work in the IE 7, and IE 8 realm, but what happens if you added say a jQuery work around for it so you only have to fix it in one place.

Lets try the folowing
[code]
$(‘a’).each(function(){
if( $(this).attr(“href”) != ” ){
var checkStr = substr($(this).attr(‘href’),0,5);
if( checkStr == ‘javas’ ){
var thisClick = $(this).attr(‘href’);
thisClick = thisClick.explode(‘:’);
$(this).bind(“click”,function(){
thisClick[1];
});
}
});
[/code]

I’m not going to assume it is showing the above code correctly so lets post what it did,.
1) loop through every a tag
2) identify those that have an href
3) if href ~ javascript grab the :function call
4) assign the href:javascript to the this click function of that a
5) test

Tags: , ,

Comments are closed.