Search code examples
jquerytimeoutbrowser-history

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;
    }

Solution

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

    setTimeout(function(){history.back();}, 3000);