Javascript 相当于 http-equiv 重定向

标签 javascript redirect meta-tags http-equiv

这两个元标记的等效项是什么:

<meta http-equiv="refresh" content="0; URL=http://www.example.com/">

<meta http-equiv="refresh" content="35; URL=http://www.example.com/">

在 JavaScript 中?

最佳答案

如果您只需要刷新,可以使用window.location.reload()

如果您需要它在 35 秒后触发,请使用 setTimeout(function() { window.location.reload(); }, 35000);

要重定向到另一个页面,您可以使用 window.location.replace('http://www.example.com') 确保浏览器后退按钮跳过上一页,或者window.location = 'http://www.example.com' 以保留浏览器历史记录。

关于Javascript 相当于 http-equiv 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37598988/

相关文章:

javascript - 如何继续检查数组直到满足特定条件

html - 有没有办法让 iFrame 中的链接重定向到其源?

bash - Unix:如何将输出添加到文件中?

html - 如何在响应式设计中禁用缩放功能?

html - jsFiddle 字符集

javascript - Jquery .load 触发两次,但被调用一次

Javascript - 我可以拦截对 document.location.href 的调用吗?

javascript - 如何从字符串的开头和结尾删除特定字符?

php - 使用 wp_redirect 重定向 wordpress 页面

python - 从只有网站 url 的元标记和 img url 中提取值。为 django 应用程序用 python 编写