避免在使用meta http-equiv标记重定向时将页面添加到浏览器历史记录中 [英] avoid a page being added to browser history when redirecting using a meta http-equiv tag

查看:413
本文介绍了避免在使用meta http-equiv标记重定向时将页面添加到浏览器历史记录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,使用以下方式重定向到所需的目标网址:

I have a web page, that redirects to the desired destination url using:

<meta http-equiv="refresh" content="0; URL=$destination.url" />

我想避免浏览器历史记录中的第一页。

I would like to avoid the first page being in the browser history.

特别是,在手机(Android,iOS等)中,我希望后退按钮跳过重定向页面。

In particular, in mobiles (Android, iOS, etc) I would like the back button to skip the redirecting page.

推荐答案

您的两个选择是使用真正的HTTP重定向,或者使用JavaScript的 location.replace

Your two options are to either use a real HTTP redirect, or to use JavaScript's location.replace.

前者更好,但如果有某种原因您不能这样做, location.replace 可以作为替代方案:

The former is better, but if there's some reason you can't do it, location.replace can work as an alternative:

document.location.replace(redirectURL)

location.replace 实际上会替换浏览器历史记录中的当前位置,因此后退按钮不会返回到重定向页面。如果你这样做,如果你希望你的任何用户没有JavaScript,你可能还希望包含一个短暂超时的元素刷新作为后备。

location.replace actually replaces the current location in the browser history, so the back button will not go back to the redirection page. If you do this you may also want to include a meta refresh with a short timeout as a fallback if you expect any of your users to not have JavaScript.

这篇关于避免在使用meta http-equiv标记重定向时将页面添加到浏览器历史记录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆