最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - When loading, the page goes on the bottom of it - Stack Overflow

programmeradmin0浏览0评论

I have an issue with my website. My page loads normally in Firefox, but when I use either Chrome or Safari, it goes to the bottom of the page and I don't understand why. I tried putting the following snippet at the beginning of the page, but no luck.

<script>

$(document).ready(function() {
    $(document).scrollTop(0);
});

</script>

Why does the page go to the bottom on loading?

I have an issue with my website. My page loads normally in Firefox, but when I use either Chrome or Safari, it goes to the bottom of the page and I don't understand why. I tried putting the following snippet at the beginning of the page, but no luck.

<script>

$(document).ready(function() {
    $(document).scrollTop(0);
});

</script>

Why does the page go to the bottom on loading?

Share Improve this question edited Apr 10, 2013 at 12:50 Darin Kolev 3,40913 gold badges33 silver badges47 bronze badges asked Apr 10, 2013 at 12:24 DikenekoDikeneko 3564 silver badges21 bronze badges 2
  • 1 Is there something in your page that gets the focus when the page is loaded? Perhaps this element is near the bottom of the page? – Borniet Commented Apr 10, 2013 at 12:26
  • It works fine for me with chrome version 26.0.1410.43 m – Sven van den Boogaart Commented Apr 10, 2013 at 12:33
Add a ment  | 

4 Answers 4

Reset to default 5

When going to your site, I get redirected to http://www.ondinevermenot.fr/#start. That means the page will try to jump to the start element.

However, the start element is absolutely positioned. Therefore, when the page tries to jump down, the start element moves down with it. Therefore the page tries to jump down again. Then the start element moves down more. They keep going down until the bottom of the page, when there is no more room.

To fix it, don't redirect to #start when your page loads.

Because of the strangeness of jumping to something that's absolutely positioned, it's probably handled differently in different browsers.

Try to have your image and other contents put inside div and set the box attribute of the div to margin:auto. works well with HTML5.

i have an alturnative work around for you and incase you ever need to get to the top of the page - you can use this javascript as an alturnative:

((IJavaScriptExecutor)webapplication).ExecuteScript("window.scrollTo(0, document.body.scrollHeight 0)");

however the other option would be to set a start up property: for example document.start("body.height = 0") something along those lines may work.

preferably id use option one as a code to start the broswer at a set height may not work so well for every browser. hope this helps.

I had 2 links to my home page in my footer. When I removed the links from my footer the problem went away.

发布评论

评论列表(0)

  1. 暂无评论