View Full Version : Problem with Javascript Redirect in Firefox

10-20-2008, 11:31 AM

I'm having a problem with getting a simple Javascript redirect to work. Basically I want it so that when the use hits the page they will straight away be redirected down to an anchor tag further down the page. My code works perfectly in IE, but not in Firefox. Here is the code I'm using:


<script type="text/javascript">
window.location = "#thelink"

HTML for anchor tag:

<a name="thelink"></a>

Any ideas on what I might be doing wrong?

Thanks in advance

10-20-2008, 11:36 AM
The name attribute is deprecated (hence, invalid) and replaced by the id attribute. The correct way to link within a document is to address any element with it's id, say

<a id="thelink"></a>

PS: You could apply the same feature on any elements, say

<h2 id="subhead">Sub head</h2>

10-20-2008, 12:09 PM
thanks but thats not working for me. I changed the name to id and I can see the # in the address bar when the page loads but it doesn't get redirected down in Firefox. When I refresh the page however it does work. Could I be missing an onload function or something in my Javascript code which is causing this to behave like this?

10-20-2008, 12:26 PM
OK, now have a try by changing
window.location = "#thelink" to

window.location = "#thelink";

10-20-2008, 01:33 PM
perfect, works well, thanks for your help :)