Hi,
I have a ASP.NET MVC app.
How do I set the scroll position of a page on page load at a defined point?
Can I do it with an anchor, if so how??
Malcolm
Hi,
I have a ASP.NET MVC app.
How do I set the scroll position of a page on page load at a defined point?
Can I do it with an anchor, if so how??
Malcolm
You just have to append #div-name at the end of the page address. Example:
http://stackoverflow.com/questions/2249475/set-page-scroll-position-on-page-load-of-mvc-app/2249506 - page address
#2249506 - div name
If you want to do it when page is loaded, you can write JavaScript:
window.location = '#2249506';
Using jQuery, when document is loaded:
<script type="text/javascript">
$(function() {
window.location = '#div-name';
});
</script>
You can use anchor tags.
When the name attribute is used, the <a>
element defines a named anchor inside a HTML document. Named anchor are not displayed in any special way. The name attribute is invisible to the reader. This attribute must appear at the end of the query string.
Named anchor syntax:
<a name="label">Any content</a>
The link syntax to a named anchor:
<a href="#label">Any content</a>
The # in the href attribute defines a link to a named anchor (http://www.mywebsite.com/mypage#label).
Example:
A named anchor inside an HTML document:
<a name="tips">Useful Tips Section</a>
A link to the Useful Tips Section from the same document:
<a href="#tips">Jump to the Useful Tips Section</a>
A link to the Useful Tips Section from another document:
<a href="http://www.w3schools.com/html_tutorial.htm#tips">Jump to the Useful Tips Section</a>