is it possible to add some jscript to a page that will locate the horizontal and vertical scrollbars on page load ... ? i'm working on someone else's asp.net 1.1 app, and (for reasons i can't figure out) the vertical scrollbar frequently locates partially down
the page ... i've looked over the code but i haven't found the culprit ... i'd like to use some jscript to implement a fix on those pages: on page load, force the vertical scroll bar to be all the way at the top.
Hi, You can put a name tag on top of the page, and then fire a Javascrip method in onload event: E.g. location.href='#top'; Alternatively, you can use RegisterStartupScript to push this script to the client across PostBack. Regards,
Hi Colt, and thanks for the response. Do you mean: ... Also: Could you talk more about RegisterStartupScript ... are you saying that this is necessary to cause the same behaviour to occur during page load for post-backs ? Thanks.
Hi, Do you mean: ... 99% correct! :) You actually use (without #)
Also: Could you talk more about RegisterStartupScript ... are you saying that this is necessary to cause the same behaviour to occur during page load for post-backs ?
You can hardcode the JavaScript method for the onload event in ASPX file, you can also write it out from server side code dynamically. E.g.
Sub Page_Load(sender As Object, e As EventArgs)
Dim locationString As String = "<script language='Javascript'>location.href='#top';<"
locationString &= "/script>"
Page.RegisterStartupScript("ScrollTop", locationString)
End Sub
so the jscript location.href='#top'; tells ie to locate the scroll-bars so that the anchor with name "top" is just-scrolled-to ... ? why is the # necessary? to distinguish the case of setting location.href to a url ?
Hi johnagrandy, you are welcome. Unfortunately I don't have all the answers but here is what I do know: ::The above Javascript is telling the browser to scroll so that the first tag in the will be shown at the top of the page. This is correct ::(Do you know
exactly when in the rendering sequence this Javascript is executed?) I am not 100% sure but I believe it is after all the HTML page elements have completely loaded. ::But what about the situation where an included CSS specifies a graphic to be placed at the
top? Using the above Javascript would mean that this graphic would be partially or completely scrolled out of view. ::Can you write Javascript to tell the browser be scrolled to the absolute top on first view of the page -- no matter what. As above, I believe
the graphic would be placed there before the onLoad event. You might try actually setting absolute position of the anchor tag, I have never done that but I think it will work?
johnagrandy
Participant
1670 Points
362 Posts
jscript to locate scrollbars
Oct 31, 2003 05:46 AM|LINK
Colt
All-Star
15569 Points
1986 Posts
ASPInsiders
MVP
Re: jscript to locate scrollbars
Oct 31, 2003 05:56 AM|LINK
johnagrandy
Participant
1670 Points
362 Posts
Re: jscript to locate scrollbars
Oct 31, 2003 07:21 AM|LINK
Colt
All-Star
15569 Points
1986 Posts
ASPInsiders
MVP
Re: jscript to locate scrollbars
Oct 31, 2003 01:07 PM|LINK
Also: Could you talk more about RegisterStartupScript ... are you saying that this is necessary to cause the same behaviour to occur during page load for post-backs ? You can hardcode the JavaScript method for the onload event in ASPX file, you can also write it out from server side code dynamically. E.g.
Sub Page_Load(sender As Object, e As EventArgs) Dim locationString As String = "<script language='Javascript'>location.href='#top';<" locationString &= "/script>" Page.RegisterStartupScript("ScrollTop", locationString) End SubRegards,johnagrandy
Participant
1670 Points
362 Posts
Re: jscript to locate scrollbars
Nov 01, 2003 03:42 PM|LINK
nickicl
Star
8230 Points
1646 Posts
Re: jscript to locate scrollbars
Nov 03, 2003 12:27 PM|LINK
johnagrandy
Participant
1670 Points
362 Posts
Re: jscript to locate scrollbars
Nov 03, 2003 03:36 PM|LINK
nickicl
Star
8230 Points
1646 Posts
Re: jscript to locate scrollbars
Nov 03, 2003 04:02 PM|LINK