刷新站点页面就像按 F5 或单击刷新按钮一样
Refresh a site page just like pressing F5 or clicking refresh button
我环顾四周,没有看到任何关于我所问的内容,只是将其关闭...
所以我正在使用 Microsoft Edge,当我 运行 我的 ASP.Net 核心网络应用程序时,我想显示一些更改。我可以按 F5 或单击刷新按钮,但页面不会闪烁,或者除了显示的数据外,它看起来不像重新加载。或者,如果我向下滚动页面,点击刷新按钮,页面就会闪烁,它 returns 回到我在点击刷新按钮之前滚动到的位置。我怎样才能在代码中做到这一点?
在 JavaScript 中,我可以使用 location.reload()
强制刷新页面,除了这似乎是一个完整的 "hard" 刷新并且不会恢复到我向下滚动到的位置。那么 F5 怎么能做到这一点而我不能呢?我想一定有办法。
我找了又找,但每个人都想把它关掉而不是打开。非常感谢任何帮助。
使用此代码刷新页面:
//code to refresh the page
var page_y = $( document ).scrollTop();
window.location.href = window.location.href + '?page_y=' + page_y;
并将此代码放在 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 );
}
});
代码来自:
我环顾四周,没有看到任何关于我所问的内容,只是将其关闭...
所以我正在使用 Microsoft Edge,当我 运行 我的 ASP.Net 核心网络应用程序时,我想显示一些更改。我可以按 F5 或单击刷新按钮,但页面不会闪烁,或者除了显示的数据外,它看起来不像重新加载。或者,如果我向下滚动页面,点击刷新按钮,页面就会闪烁,它 returns 回到我在点击刷新按钮之前滚动到的位置。我怎样才能在代码中做到这一点?
在 JavaScript 中,我可以使用 location.reload()
强制刷新页面,除了这似乎是一个完整的 "hard" 刷新并且不会恢复到我向下滚动到的位置。那么 F5 怎么能做到这一点而我不能呢?我想一定有办法。
我找了又找,但每个人都想把它关掉而不是打开。非常感谢任何帮助。
使用此代码刷新页面:
//code to refresh the page
var page_y = $( document ).scrollTop();
window.location.href = window.location.href + '?page_y=' + page_y;
并将此代码放在 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 );
}
});
代码来自: