Umar
Umar

Reputation: 99

How do i load page with default hash (ID) content?

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.

Upvotes: 3

Views: 374

Answers (3)

The Alpha
The Alpha

Reputation: 146201

You may try this (Check MDN)

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

DEMO.

Upvotes: 1

Stefan
Stefan

Reputation: 3900

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

<script type='text/javascript'>
     document.getElementById("home").scrollIntoView();
</script>

Upvotes: 1

Jean-Paul
Jean-Paul

Reputation: 21170

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?

Upvotes: 0

Related Questions