在按返回按钮时忽略重定向页面。

3
我有一个“加载页面”,用于提示用户系统正在搜索。 当用户按下返回按钮时,我想跳过此页面并将其重定向到第一页。
如何实现? 谢谢。
3个回答

3

我刚刚使用了 windows.location.replace(newUrl),它可以将页面从历史记录中移除并修复它。


0

你可以在加载页面检查引荐来源并匹配。如果引荐来源是“后续”加载页面的页面,那么可以假定用户按了返回按钮。

你可以在服务器端或javascript中实现此功能,以下是JS的示例(伪代码):

if ( document.referrer.test(/[URL]/) ) {
    window.location = '/';
}

感谢您的帮助。 在IE8上,当我按下返回按钮时,它告诉我referrer是第一页。 - Yaron Ohana

-2
使用JavaScript Response.Cache.SetNoStore(); 或 window.history.forward(1);
这将禁用返回按钮功能。 同时保持一些会话值,如果单击返回按钮,则将其设置为空。像下面这个例子。
<%
  Response.Buffer = True
  Response.ExpiresAbsolute = Now() - 1
  Response.Expires = 0
  Response.CacheControl = "no-cache"

  If Len(Session("FirstTimeToPage")) > 0 then
    'The user has come back to this page after having visited
    'it... wipe out the session variable and redirect them back
    'to the login page
    Session("FirstTimeToPage") = ""
    Response.Redirect "/Bar.asp"
    Response.End
  End If
%>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接