go to hi . . hi text here but I ...">

Go to item automatically when page loads

I have such elements on the page

<a href="#hi">go to hi</a> . . <a name="hi">hi text here</a> 

but I would like users to first go to "hello text here" when the page loads. how to do it?

+2
source share
4 answers

I suggest you check another hash first before moving your users browser to focus another element:

 if (!document.location.hash){ document.location.hash = 'hi'; } 

JS Fiddle demo .

By the way, you can use the hash (the part after # in the URL) to go to any element with id , you do not need to use named-anchors ( <a name="hi">...</a> ).

+5
source

Either you can use the URL with the anchor (mysite.com/#hi), or use javascript:

 document.getElementById('hi').scrollIntoView(true); 

Please note that you must use an identifier, not a name.

+3
source

You can use jQuery with your scrollTo plugin and then write something like this:

 $.scrollTo("a[name = hi]"); 

It should work fine.

+1
source

I think it would be useful to work with anchors:

 <a name="hi">here goes the text information what you like</a> 

Create a link to the "hi" section inside the same document:

 <a href="#hi">Go to hi</a> 

Or create a link to the "hi section" from another page:

 <a href="http://www.stackoverflow.com/html_links.htm#hi"> Visit the hi Section</a> 
+1
source

All Articles