admin管理员组

文章数量:1287791

With the code below I can make a 'back' button, but is there a way of making the link require that the last page was part of the current site?

$(document).ready(function(){
    $('a.back').click(function(){
        parent.history.back();
        return false;
    });
});

If the last page wasn't part of the current site then ideally id like to be able to specify a backup link.

Thanks

With the code below I can make a 'back' button, but is there a way of making the link require that the last page was part of the current site?

$(document).ready(function(){
    $('a.back').click(function(){
        parent.history.back();
        return false;
    });
});

If the last page wasn't part of the current site then ideally id like to be able to specify a backup link.

Thanks

Share Improve this question edited Mar 30, 2011 at 18:21 zzzzBov 179k56 gold badges327 silver badges371 bronze badges asked Mar 30, 2011 at 18:20 EvanssEvanss 23.2k100 gold badges322 silver badges555 bronze badges 2
  • 2 Do you have a good reason for trying to mimic behavior already performed by the browser? – zzzzBov Commented Mar 30, 2011 at 18:22
  • The short answer is 'because my client has asked me'. Its for a 'continue shopping' link so it should go back to the previous category. The issue is that there are 2 different potential categories for each product. – Evanss Commented Mar 30, 2011 at 18:31
Add a ment  | 

2 Answers 2

Reset to default 8

How about using document.referrer?

$(document).ready(function(){
    $('a.back').click(function(){
        if(document.referrer.indexOf(window.location.hostname) != -1){
            parent.history.back();
            return false;
        }
    });
});

Please don't do this.

But you could use a cookie

psuedo code

if !cookie_exists()
    disable_back_button()
    create_cookie()

Then delete the cookie when the user leaves.

Referrer can be edited, so I don't remend that

but I also don't remend doing this at all, its annoying.

本文标签: JavascriptjQuery back buttonso long as last page was part of current siteStack Overflow