3

I have a page, named as index.html and i want to load it as index.html#home

Because i do have few elements with different ID's, and i want to load the #home content by default.

So when we hit index.html page it will reload to index.html#home (unless if no hash is specified in the URL)

How its possible? and forgive my english.

Umar
  • 99
  • 2
  • 8

3 Answers3

1

Put this in the (NOT head - see comments) bottom of your html page:

<script type='text/javascript'>
     document.getElementById("home").scrollIntoView();
</script>
Stefan
  • 3,850
  • 2
  • 26
  • 39
1

You may try this (Check MDN)

if(!window.location.hash) {
    location.hash = '#home';
}

DEMO.

The Alpha
  • 143,660
  • 29
  • 287
  • 307
0

If what you're trying to do is scroll to a div on pageload, I suggest reading (/applying) this:

jQuery: how to scroll to certain anchor/div on page load?

Community
  • 1
  • 1
Jean-Paul
  • 19,910
  • 9
  • 62
  • 88