17 August, 2007

Javascript : location.href problem in FireFox

The location.href is working fine in IE(Internet Explorer), but not in FireFox or Safari. There are two solutions :

1) Use location.replace('http://www.theURL.com')
- The replace method loads the specified URL over the current history entry, it meant after the replace method is used, the user cannot navigate to the previous URL by using browser's Back button.

2) Use window.location= 'http://www.theURL.com'; return false;
- It will allow you to navigate to the previous URL by using browser's Back button.

Eg:
<tr>
<td onclick="window.location='http://www.yahoo.com'; return false;" style="cursor: pointer;">
</td>
</tr>


3) Another solution provided by reader (updated 10/08/2009):
- Use location.href= 'http://www.theURL.com';

4 comments:

Anonymous said...

very useful

玩耍 said...

Hi I'm try this

location.href = 'url.com';

not this

location.href("url.com");

can work with Safari

Jason said...

hi 玩耍, thanks for the new solution.

Anonymous said...

Hello! I just wish to give a huge thumbs up for the nice info you might have here on this post.
I shall be coming back to your weblog for more soon.


Here is my web site: caster semenya wikipedia free encyclopedia