My page adds # to the html programatically and have this in the tag
function InsertTag(){
//Add <a name="spot"></a> to the middle of this document
}
window.addEventListener('load', InsertTag, false);
my question is how can I make the document then jump to #spot?
Here’s a suggestion: use id’s instead. If you have:
Then
page.html#somethingwill take you straight to that div. It doesn’t have to be adiv, it can be used on any element. If you can manipulate the DOM to add that anchor, I am pretty sure you’ll be able to do this.Now… To get there, you can use:
See it in action here: http://ablazex.com/demos/jump.html
There are subtle differences between the methods. Eg: The first one will cause the location on the address bar to be updated, the second one won’t.
If you want it to look nicer you can use a jQuery plugin, like ScrollTo.