开发者

HTML a tag bookmark

I want the web page to start at the bottom of the screen on load of page from a link. To do this i just put #bottom at the end of the url i want to load.

example: www.something.com#bottom

This seems to work开发者_JS百科

I also want to be able to have a go to bottom of page button.

My code is:

<a href="#bottom">Go to bottom of page</a>
<a name="bottom"></a>

This will load the page at bottom but when i click on the go to bottom it reloads the page and loses all work that has been done. The go to bottom button will work fine with no reload now until the page reloads again. Then problem starts again.

Any advice is much appreciated.


I believe it should be id, not name.

<a href="#bottom">Go to bottom of page</a>
<a id="bottom"></a>

Edit

Nope, I was wrong. It shouldn't matter.


Unfortunately you can't do this with a link, because that inherently means that you have to reload the page.

  • What you want to do is use Javascript to scroll.

Your go to bottom button could implement the solution described under the section titled 'Scroll Directly to a Particular Point'


Thanks for all the help. I figured it out though this works

function ScrollTo(Aobj){
obj = document.getElementById(Aobj);
try{
    var objpos = ObjectPosition(obj);
}catch(e){}
try{
    scroll(0,objpos[1]);
}catch(e){}
try{
    window.scrollTo(0,objpos[1]);
}catch(e){}

}

function ObjectPosition(obj) {
var curleft = 0;
  var curtop = 0;
  if (obj.offsetParent) {
        do {
              curleft += obj.offsetLeft;
              curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
  }
  return [curleft,curtop];

}

Got it from: http://www.michaelapproved.com/articles/scroll-to-object-without-leaving-page/

<span style="color:#03F" onclick="ScrollTo('vsresponse')"><u>goto bottom</u></span>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜