deadimp Posted September 28, 2007 Share Posted September 28, 2007 It's a basic question, but: What's the best way to have javascript focus on a link without adding the identifier 'clause' to the end of an url? Example: index.html Random html... <a id='anchor' href='...'>Anchor</a> More random html To have a browser focus on the anchor via the url, you just add #anchor to your url. This is what I've come up with: <script language='javascript'> function anchor_focus(name) { var obj=document.getElementById(name); obj.focus(); obj.blur(); } //Example anchor_focus("anchor"); </script> That scrolls it into view, and of course deselects it to mimick appending "#anchor" to the url. It's worked on Firefox, IE, and Opera (all Windows). Any other suggestions? Quote Link to comment Share on other sites More sharing options...
fenway Posted October 1, 2007 Share Posted October 1, 2007 Why not just focus on the first child element after it? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.