How can I make a link which goes to the last page visited which was part of the current site?

Another way of saying this is I need a link which is like the browser's back button, unless the last page visited was a different website. If this is the case the link could either go to the last page on the current site that was visited, or an arbitrary back up could be used.

Thanks

Comments

mcfilms’s picture

<A HREF="javascript:history.go(-1)"> [Go Back]</A>

This takes you back to the previous page. Stopping a visitor from backing out of your site is a bigger challenge. Perhaps an if/then code to check and see if history.go(-1) will leave the current site or not.

Good luck!

A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com

jdln’s picture

Copying the code straight into a block (with full html) doesn't work, instead I get this link:

http://mysite/javascript%3Ahistory.go%28-1%29

Thanks

mcfilms’s picture

Are you using a WYSIWYG? Can you disable it for that page?

A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com

jdln’s picture

Im not using WYSIWYG for full html and the only filter I have is path logic.
Thanks

mcfilms’s picture

I don't know what to say. I just tried it on my site just now and it works.

A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com

jdln’s picture

Putting the code in my tpl file means it does work. Thanks

Anyone have any ideas about the if/then code?

jdln’s picture

Ive done it with jquery. If the last page was not part of the current site then the link isn't changed so the backup is stated through drupal.

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