3 Replies - 3337 Views - Last Post: 24 October 2010 - 03:09 PM

#1 moneyg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-July 05

Troubleshoot: using history.back on a redirect page

Posted 13 October 2010 - 06:26 PM

Hi, just trying to get this to work. Code is inserted into document head. I am using this on a confirmation page that comes up after submitting a form, I want the page to redirect to the previous page. I am also wanting to add a timer indicator to the page as feedback to the user.

<script type="text/javascript">
redirTime = "5000";
redirURL = "history.go(-1)";
function redirTimer() { self.setTimeout("self.location.href redirURL;",redirTime); }
</script>


also tried:

<script type="text/javascript">
redirTime = "5000";
redirURL = "history.back()";
function redirTimer() { self.setTimeout("self.location.href redirURL;",redirTime); }
</script>


This code is not functioning in Firefox. Any help greatly appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Troubleshoot: using history.back on a redirect page

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4309
  • View blog
  • Posts: 12,088
  • Joined: 18-April 07

Re: Troubleshoot: using history.back on a redirect page

Posted 13 October 2010 - 10:34 PM

Try sticking the redirect code into its own function and then call the function from setTimeout...

// Our function that goes back in history
function redirect() {
    history.go(-1);
}

// Call function from timer
setTimeout('redirect()',5000);

// Or to simplify this will work too...

setTimeout('history.go(-1)',5000);



Here is a simple code to show you how to go back in the history after 5 seconds. It works in both IE and Firefox and I am sure all the other popular browsers. Enjoy!

:)

This post has been edited by Martyr2: 13 October 2010 - 10:36 PM

Was This Post Helpful? 0
  • +
  • -

#3 forest51690  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 58
  • View blog
  • Posts: 340
  • Joined: 20-March 09

Re: Troubleshoot: using history.back on a redirect page

Posted 17 October 2010 - 07:55 PM

function redirTimer() { self.setTimeout("self.location.href redirURL;",redirTime); }


Here is where your error is. Notice that there is no assignment operator "=" in setTimeout's first parameter "self.location.href redirURL;". Try that. Also, what I would do is stick the command in an anonymous function, like so.

function redirTimer() { self.setTimeout(function(){self.location.href = redirURL;},redirTime); }


Let me know if just adding the assignment operator works though...
Was This Post Helpful? 0
  • +
  • -

#4 moneyg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-July 05

Re: Troubleshoot: using history.back on a redirect page

Posted 24 October 2010 - 03:09 PM

Thanks guys, I ended up using Martyr's code, works fine. Couldn't get the code to work adding the assignment operator.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1