重新加载到页面顶部

重新加载到页面顶部

本文介绍了重新加载到页面顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已解决将此添加到html:

SOLVEDadd this to the html:

<body onload="location.href='#menu'">

这是唯一的解决方案,而不是滚动问题的重复.... pff.

Its the only solution and not a duplicate of the scroll question....pff.

我已经编辑了这个问题,希望SO社区能够重新审视它.假设重复的问题中的解决方案均无效,或者我使用的方法不正确.我用两个解决方案发布了代码,以表明我正在尝试.请帮忙!

I have edited this question in hopes that the SO community would revisit it. None of the solutions in the supposed duplicate question work or I am using them incorrectly. I posted my code with two of the solutions to show that I am trying. Please help!

我找不到超级基本的JavaScript问题...我正在从试验中学习,主要是错误和StackOverflow.

Super basic javaScript question I can't find.....I'm learning from trial, mostly error, and StackOverflow.

刷新后,我想返回页面顶部(F5或重新加载浏览器或以其他任何方式可以重置页面).我相信这是浏览器工作的旧"方式,但是当我刷新时,我停留在页面上的同一位置.我正在Chrome浏览器中进行测试.当然,我希望在所有浏览器中都具有这种行为.

When I refresh I want to return to the top of the page (F5 or browser reload or any other way the page can be reset). I believe this was the 'old' way browsers worked but when I refresh I stay in the same place on the page. I'm testing in Chrome. Of course I would like this behavior in all browsers.

在这种情况下,我正在构建一个单页应用程序.大多数移动用户将永远不会使用刷新/重新加载,因为刷新/重新加载已被隐藏在汉堡包中,但是我想通过回到原始状态来处理此事件.在这种情况下,<div data-role="page" id="menu">.

In this case I am building a single page app. Most mobile users will never use the refresh/reload as it is buried in the hamburger, but I would like to handle this event by going back to the home state. In this case the <div data-role="page" id="menu">.

我正在使用jquery,但我想确定并学习javascript.

I am using jquery but I want to make sure and learn javascript.

谢谢大家.

代码:

 document.ready = init;

函数init(){

var button = $('#facultyButton')
    ,facList = $('#facultyList')
    ,search = $('#facSearch')
    ,monikerBox = $('.monikerBox')
    ,events = $('#events')
    ,ajaxString = "http://stage.webscope.com/veith/dev/ajax.pl?"
    ,html = "";

//executed on init
console.log('page init');
 $('html').scrollTop(0);

//事件

$(window).on('load',function(){
    $('html, body').scrollTop(0);
});
button.click(function(){
    var value = "a";

推荐答案

页面加载完成后,窗口的load事件仅运行一次.因此,通过这种方式,您可以确保在页面加载后,无论何种原因(第一次查看或刷新),页面都将运行.

The window's load event only runs once right after the page is done loading. So this way you can be sure that after the page loads no matter what reason (first view or refresh) it will run.

$(window).on('load', function(){
    $('html, body').scrollTop(0);
});

这篇关于重新加载到页面顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 21:13