avoid a page being added to browser history when redirecting using a meta http-equiv tag

匿名 (未验证) 提交于 2019-12-03 03:08:02

问题:

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.

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

回答1:

Your two options are to either use a real HTTP redirect, or to use JavaScript's 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 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.



回答2:

You can't.

If you want to redirect, use an HTTP redirect. <meta> redirects have many flaws, and this is one of them.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!