在通过javascript返回之前测试浏览器的历史记录吗? [英] Test browser history before going back via javascript?

查看:66
本文介绍了在通过javascript返回之前测试浏览器的历史记录吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用一些JavaScript向我的网站上的后退按钮添加额外的功能.现在,我有一组看起来像这样的javascript:

I'm playing around with using some javascript to add extra functionality to a back button on my website. Right now I have a set of javascript that looks like this:

$(".back-link a").live("click", function(){
    history.go(-1);
    return false;
});

现在,它工作得很好,但我正在尝试使其尽可能地防弹,我预见的一个问题是,如果有人登陆到项目页面并且没有通过我的主页来访问它,则返回他们的主页.历史记录将使他们离开我的网站.显然,这不是我想要的.

Now, it works great but I'm trying to make it as bulletproof as possible and one issue I foresee is that if someone lands on a project page and hasn't come to it via my home page then going back in their history one step will take them off my site. Obviously, this isn't what I want.

我的猜测是执行if语句很简单,但是我不确定要测试什么或如何对其进行测试.我想我可以测试一下以确保URL的基础是我的网站,但是我不确定如何.

My guess is it would be a simple case of doing an if-statement but I'm not sure what or how to test for it. I suppose I could just test to make sure the base of the URL is my site but I'm not sure how.

任何提示或指示都很好.

Any tips or directions would be great.

推荐答案

不,不是那样简单.您可以使用历史记录集合进行前进或后退,但无法在历史记录中获取URL.

No, it's not at simple as that. You can use the history collection to go back or forward, but you can't get the URLs in the history.

您可以获得的关于用户来源的唯一信息是请求标头中的HTTP_REFERER字符串,但是您必须使用服务器端代码来获取.

The only information that you can obtain about where the user comes from is the HTTP_REFERER string in the request header, but you have to use server side code to get that.

这篇关于在通过javascript返回之前测试浏览器的历史记录吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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