【发布时间】:2016-11-11 22:12:02
【问题描述】:
我把这个脚本放到index.html中
<script type="text/javascript">
window.history.pushState('other.html', 'Other Page', 'other.html');
window.history.pushState('index.html', 'Initial Page', 'index.html');
window.addEventListener("popstate", function(e) {
if (document.URL.indexOf("other.html") >= 0) {
document.location.href = document.location;
}
});
</script>
在 other.html 文件中,我将此行放在 head 部分的元标记中。
http-equiv="refresh" content="0;URL='http://example.com/'
因此,当我第一次运行并单击浏览器后退按钮时,它将转到 other.html 并将我重定向到此链接 http://example.com/,当我再次单击浏览器后退按钮时,它会将我重定向到旧索引。 html
这工作正常。我需要在这里制作 HTML 元重定向的等效代码。我不想将此标记放入 other.html 中,并且我想创建现在执行 html 元标记的 javascript 代码。
这可能吗?任何帮助将不胜感激。
【问题讨论】:
-
您已经知道如何使用
location进行重定向。你试过用那个吗?如果元标记方法有效,它有什么问题?
标签: javascript jquery html redirect