简体   繁体   English

刷新站点页面,就像按 F5 或单击刷新按钮一样

[英]Refresh a site page just like pressing F5 or clicking refresh button

I have looked around and don't see anything about what I'm asking, only turning this off...我环顾四周,没有看到我在问什么,只是将其关闭...

So I'm using Microsoft Edge and when I run my ASP.Net Core web app, there's changes that I want to show.所以我正在使用 Microsoft Edge,当我运行我的 ASP.Net Core Web 应用程序时,我想显示一些更改。 I can press F5 or click the refresh button and the page doesn't flash or it doesn't look like it reloads except for the data showing up.我可以按 F5 或单击刷新按钮,页面不闪烁,或者看起来不像重新加载,除了显示的数据。 Or if I scroll down the page, hit the refresh button where the page then does flash, it returns back to the spot that I was scrolled to before hitting refresh button.或者,如果我向下滚动页面,点击页面闪烁的刷新按钮,它会返回到我在点击刷新按钮之前滚动到的位置。 How can I make this happen in code?我怎样才能在代码中做到这一点?

In JavaScript I can force a page refresh with location.reload() except this seems to do a complete "hard" refresh and does not resume back to the position I was scrolled down to.在 JavaScript 中,我可以使用location.reload()强制页面刷新,除了这似乎执行了完整的“硬”刷新并且不会恢复到我向下滚动到的位置。 So how can F5 do this but I can't?那么 F5 怎么能做到这一点而我不能呢? I assume there must be a way.我想一定有办法。

I've searched and searched but everyone wants to turn this off not on.我搜索了又搜索,但每个人都想关闭而不是打开。 Any help is much appreciated.任何帮助深表感谢。

Use this code to refresh the page:使用此代码刷新页面:

//code to refresh the page
var page_y = $( document ).scrollTop();
window.location.href = window.location.href + '?page_y=' + page_y;

And place this code in a script tag at the bottom of body :并将此代码放在body底部的script标记中:

//code to handle setting page offset on load
$(function() {
    if ( window.location.href.indexOf( 'page_y' ) != -1 ) {
        //gets the number from end of url
        var match = window.location.href.split('?')[1].match( /\d+$/ );
        var page_y = match[0];

        //sets the page offset 
        $( 'html, body' ).scrollTop( page_y );
    }
});

Code from: https://stackoverflow.com/a/17643341/6152171代码来自: https : //stackoverflow.com/a/17643341/6152171

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM