Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go back to previous page after a delay

I want to go to the previous page after a 2 second delay using jQuery. I thought maybe I could do it this way but I think 'm using this in the wrong context. Code doesn't do anything worthwhile.

function goBack() {
    $(this).delay(3000, function(){
      history.back();}
    return false;
    }
like image 452
Chamilyan Avatar asked Sep 17 '11 02:09

Chamilyan


2 Answers

The second argument to delay() is a queueName, not a function to run after the delay. Use setTimeout instead:

setTimeout(function(){history.back();}, 3000);
like image 105
Digital Plane Avatar answered Oct 18 '22 22:10

Digital Plane


JS Code

setTimeout('history.go(-1)', 3000);
like image 28
Ciprian Radu Avatar answered Oct 18 '22 22:10

Ciprian Radu