Question

Is there a way to force an anchor to be at the middle or bottom of the screen upon press?

The reason i ask is because i have an ASP.net document which will load from a database and give a long form. I have an anchor situated at the top and it works great, except that it takes the browser to the start of the ASP form instead of the top of the page. which is to be expected. but is there any way around that?

example of what happens currently:

OnButtonClick:     
                      banner (offscreen)
    --------------    --------------
    |banner      |    |anchor      |
    |anchor      |    |asp doc     |
    |asp doc     |    | .          |
    | .          |    | ..         |
    | ..         |    | ...        |
    | ...        |    |button      |
    |button      |    |            |
    |____________|    |____________|

i Should probably add:

I can't add an anchor to the html document itself because this ASP form will not be in a constant location. it could be on as many as 10 different websites. which different layouts.

Thanks Banana for a working Solution:

<script>
function anchor() {
    $(window).scrollTop(0);
}
</script>

<a onclick="anchor()">
    <asp:Image ID="TopOfPageButton" ImageUrl="~/Images/topofpage.gif" runat="server" />
</a>
Was it helpful?

Solution

you could navigate to any element if you add #[elemendID] to the query string

for example, u have an element with id="banana"

you could focus on it by loading your page this way:

http://blablablablabla.com/blabla.aspx#banana

EDIT:

or like was suggested below, you could use jquery. you could attach a javascript function to the button's onClientClick event, and in that function execute

$(window).scrollTop(0);

OTHER TIPS

you could try to link it to a common element that appears in every html document like

<div ID="nav">

this way all the pages will go up to the top.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top