开发者

Test browser history before going back via 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.

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.


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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜