Sunday, January 13, 2008

How can a web page go to the bottom end as soon as it is loaded?

I needed to get a loaded web page to scroll down to the bottom of a long page. I was able to make that happen using some basic JavaScript. Here's my solution:

1) Place the following HTML at the page loaction where you want to go to automatically:

<a id="bottom" name="bottom"></a>

2) Add the following ASP.NET code that triggers some very basic JavaScript:

StringBuilder sb = new StringBuilder();

sb.Append("<script language='javascript' >");

sb.Append("window.location.href = '#bottom';");


ClientScript.RegisterStartupScript(typeof(Page), "Focus", sb.ToString());

Although thic technique pertains to ASP.NET 2.0, it really can be implemented in any other server-side technology.

No comments:

Post a Comment