Keep the original position of the scroll bar after page refreshing

Source: Internet
Author: User

I found a pure JS version and made some modifications to improve it. To download it, I only need to add a line in the page_load event in codebind.CodeSo that JS can be referenced. The Code is as follows:

Page_load
Page. registerstartupscript ("scroll", "<script language = JavaScript> Init () </SCRIPT> ");

JS script
Function getfilename ()
{
VaR url = This. Location. href
VaR Pos = URL. lastindexof ("/");
If (Pos =-1)
Pos = URL. lastindexof ("//")
VaR filename = URL. substr (Pos + 1)
Return filename;
}

Function fnload ()
{
With(registry.doc ument. Body)
{
Addbehavior ("# default # userdata ");
Load ("scrollstate" + getfilename ());
Scrollleft = getattribute ("scrollleft ");
Scrolltop = getattribute ("scrolltop ");
}
}

Function fnunload ()
{
With(registry.doc ument. Body)
{
Setattribute ("scrollleft", scrollleft );
Setattribute ("scrolltop", scrolltop );
Save ("scrollstate" + getfilename ());
}
}

Window. onload = fnload;
Window. onUnload = fnunload;

function Init ()
{< br> with(window.doc ument. body)
{< br> addbehavior ("# default # userdata");
load ("scrollstate" + getfilename ();
scrollleft = 0;
scrolltop = 0;
setattribute ("scrollleft", 0);
setattribute ("scrolltop", 0 );
Save ("scrollstate" + getfilename ();
}< BR >}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.