Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用history.pushState()时刷新原始url_Javascript_Jquery - Fatal编程技术网

Javascript 使用history.pushState()时刷新原始url

Javascript 使用history.pushState()时刷新原始url,javascript,jquery,Javascript,Jquery,原始Url:domain/dashboard.htm 我使用pushState()替换它: 所以现在在地址栏上我可以看到“domain/teachers.htm” 但当我按F5或刷新页面,然后浏览器刷新“domain/teachers.htm”,这是不存在的真实,我得到的页面未找到错误 在此阶段,浏览器应刷新原始URL,即“domain/dashboard.htm”并显示内容 有什么方法可以这样做吗?创建“teachers.htm”页面,在页面加载(javascript)方法中,将其重定向回“d

原始Url:domain/dashboard.htm

我使用pushState()替换它:

所以现在在地址栏上我可以看到“domain/teachers.htm”

但当我按F5或刷新页面,然后浏览器刷新“domain/teachers.htm”,这是不存在的真实,我得到的页面未找到错误

在此阶段,浏览器应刷新原始URL,即“domain/dashboard.htm”并显示内容


有什么方法可以这样做吗?

创建
“teachers.htm”
页面,在页面加载(javascript)方法中,将其重定向回
“domain/dashboard.htm”
,这样,如果有人按F5,它将返回到
“dashboard.htm”而不是
“teachers.htm”

保存原始URL,然后替换它

var originalUrl = window.location.href;
window.history.pushState("", "", 'teachers.htm');
window.location = originalUrl;
或写

window.history.back();

然后刷新页面

保存原始URL>在地址栏中更改URL>再次将位置设置为originalUrl,因此在这一点上发生的是从开始的循环一次又一次地运行
window.history.back();