Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Jumping to dynamically created named anchors in IE (JavaScript)

Jumping to dynamically created named anchors in IE (JavaScript)

Scheduled Pinned Locked Moved Web Development
javascriptcomquestion
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    This is driving me nuts. I have some JavaScript that creates a bunch of named anchors on-the-fly using code like this:

    var a = document.createElement("a");
    a.name = "my_anchor";
    document.body.appendChild(a);

    Later on I have some code that will jump to the anchor, e.g.:

    window.location = "#my_anchor";

    Works fine in Firefox, Opera and Safari. In IE7 nothing happens - it acts as if the named anchor doesn't exist. Anyone ever come across this before?


    Kicking squealing Gucci little piggy.
    The Rob Blog

    B 1 Reply Last reply
    0
    • L Lost User

      This is driving me nuts. I have some JavaScript that creates a bunch of named anchors on-the-fly using code like this:

      var a = document.createElement("a");
      a.name = "my_anchor";
      document.body.appendChild(a);

      Later on I have some code that will jump to the anchor, e.g.:

      window.location = "#my_anchor";

      Works fine in Firefox, Opera and Safari. In IE7 nothing happens - it acts as if the named anchor doesn't exist. Anyone ever come across this before?


      Kicking squealing Gucci little piggy.
      The Rob Blog

      B Offline
      B Offline
      badgrs
      wrote on last edited by
      #2

      I managed to reproduce this and have no idea why it doesn't work, theres obviously something fishy going on (well, it is IE after all). To get it to work I had to set the ID of the anchor instead.

      a.id = "my_anchor";
      
      L 1 Reply Last reply
      0
      • B badgrs

        I managed to reproduce this and have no idea why it doesn't work, theres obviously something fishy going on (well, it is IE after all). To get it to work I had to set the ID of the anchor instead.

        a.id = "my_anchor";
        
        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Thanks! Yes, that works a treat in all the browsers I tried.


        Kicking squealing Gucci little piggy.
        The Rob Blog

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups