2007-08-17

Javascript: location.href problem in FireFox

The location.href is working fine in IE(Internet Explorer), but not in FireFox or Safari. 
There are few 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.
    E.g.:
    <tr>
         <td onclick="window.location='http://www.theURL.com'; return false;"                     style="cursor: pointer;">
         </td>
    </tr>


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

4 則留言:

匿名 說...

very useful

玩耍 說...

Hi I'm try this

location.href = 'url.com';

not this

location.href("url.com");

can work with Safari

Jason 說...

hi 玩耍, thanks for the new solution.

匿名 說...

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