Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Sep 2004
    Posts
    96
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Problem with Javascript Redirect in Firefox

    Hi,

    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:

    Javascript:
    Code:
    <script type="text/javascript">
    <!--
    window.location = "#thelink"
    //-->
    </script>
    HTML for anchor tag:
    Code:
    <a name="thelink"></a>

    Any ideas on what I might be doing wrong?

    Thanks in advance

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    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
    Code:
    <a id="thelink"></a>
    PS: You could apply the same feature on any elements, say
    Code:
    <h2 id="subhead">Sub head</h2>
    Last edited by abduraooft; 10-20-2008 at 11:41 AM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Sep 2004
    Posts
    96
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    OK, now have a try by changing
    window.location = "#thelink"
    to
    Code:
    window.onload=function(){
    window.location = "#thelink";
    }
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    New Coder
    Join Date
    Sep 2004
    Posts
    96
    Thanks
    1
    Thanked 0 Times in 0 Posts
    perfect, works well, thanks for your help


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •