...

View Full Version : javascript:history.back(-1) question.



mwx6205
09-28-2012, 09:42 AM
Hi guys,


javascript:history.back(-1)

This code works in Chrome, but not for Mozilla & IE9. Anyone any idea?

Thanks & appreciate ;)

devnull69
09-28-2012, 10:10 AM
It works perfectly well in Firefox and IE8 for me. What is the context in your case? Where do you call it?

mwx6205
09-28-2012, 10:28 AM
Hi devnull69,

Oh no, how come i got problem :'(

This is the tag here:

<input type="button" value="No" onClick="location.href='javascript:history.back(-1);'">

I want to get back values to the form when I click No button.

Any idea?

devnull69
09-28-2012, 10:46 AM
Try this


<input type="button" value="No" onclick="history.back(-1);" />

mwx6205
09-28-2012, 11:58 AM
Hi devnull69,

Still cannot, IE says "Webpage has expired". :(

Mozilla go back the form without values :(

and the worse for now is my Chrome also can't populate back the values already :(

help~~

devnull69
09-28-2012, 12:12 PM
Ok ... so what you actually WANT to do is not history.back (which is exactly what happens when you click the browser back button) but instead you want to retrieve the previously entered values into your form inputs.

You could take a look at cookies or localStorage.

mwx6205
09-28-2012, 12:32 PM
I want to retrieve the previously entered values to my form inputs by using history.back(-1) but I have no idea why it doesn't work.

Perhaps, I have to check for cookies or localStorage or use session on it.

Thanks again :)

VIPStephan
09-28-2012, 02:20 PM
I want to retrieve the previously entered values to my form inputs by using history.back(-1) […]

This is not how this method works. history is an object that adds an entry (a visited page) to the browser history. What you have done on/with that page after it has loaded doesn’t matter to the history entry. And if you have sent a form on the previous page, this page is expired and/or you need to reload the page in its original state. history.back() is the same as clicking the back button of the browser and different browsers work differently, i. e. some might store the entered data, and some might not. You shouldn’t rely on this to start with.

Rather, you need to create a link or another form that submits the entered values back to the previous page, but in reality, from a browser history point of view, this isn’t the previous page, this is a new entry in the browser history; like, you’re going to the next page which is looking exactly like the previous one, with the values entered.

mwx6205
09-28-2012, 04:06 PM
Hi VIPStephan,

Oh I see, thanks for your awesome sharing ;) Appreciate .. !



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum