Wednesday, April 28, 2010

Fix : Location.href not working in IE 6

We recently tried to do a post back of a page based on a user input in a text box, the postback will be triggered by a ASP LinkButton. ASP Linkbutton renders as an anchor tag with the href populated with javascript:WebForm_DoPostBackWithOptions. So the challenge is to set the window.location to the javascript:WebForm_DoPostBackWithOptions

window.location= javascript:WebForm_DoPostBackWithOptions .. . ..

The location can be a URL too, in our case it is just a post back script

It works like a charm in IE 8 but it doesn't even show a sign in IE 6. We tried many variations window.location=, window.location.href= ,window.location.href.assign but nothing worked out.

After few hours of googling and surfing the web we found that we need to add the following line to get it worked in IE 6


At last the final code looked like this

if (evt.keyCode == 13)
window.event.returnValue = false;
window.location = '";
return false;

hope this helps someone .. .

No comments: