wp_page_reload_on_back_button_js()
云策文档标注
概述
wp_page_reload_on_back_button_js() 函数用于在用户通过浏览器后退或前进按钮导航到页面时,输出 JavaScript 代码以重新加载页面,确保页面内容为最新保存版本。
关键要点
- 主要用于编辑文章和新建文章页面,防止从浏览器缓存加载旧数据。
- 脚本应优先在 head 部分运行,以保证页面内容及时更新。
- 自 WordPress 4.6.0 版本引入,是核心功能的一部分。
原文内容
Outputs JS that reloads the page if the user navigated to it with the Back or Forward button.
Description
Used on the Edit Post and Add New Post screens. Needed to ensure the page is not loaded from browser cache, so the post title and editor content are the last saved versions. Ideally this script should run first in the head.
Source
function wp_page_reload_on_back_button_js() {
?>
if ( typeof performance !== 'undefined' && performance.navigation && performance.navigation.type === 2 ) {
document.location.reload( true );
}
Changelog
| Version | Description |
|---|---|
| 4.6.0 | Introduced. |