Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jun 2012
    Posts
    44
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Question javascript:history.back(-1) question.

    Hi guys,

    Code:
    javascript:history.back(-1)
    This code works in Chrome, but not for Mozilla & IE9. Anyone any idea?

    Thanks & appreciate

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    It works perfectly well in Firefox and IE8 for me. What is the context in your case? Where do you call it?

  • #3
    New Coder
    Join Date
    Jun 2012
    Posts
    44
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Hi devnull69,

    Oh no, how come i got problem :'(

    This is the tag here:
    Code:
    <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?

  • #4
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    Try this
    Code:
    <input type="button" value="No" onclick="history.back(-1);" />

  • #5
    New Coder
    Join Date
    Jun 2012
    Posts
    44
    Thanks
    17
    Thanked 0 Times in 0 Posts
    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~~

  • #6
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    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.

  • #7
    New Coder
    Join Date
    Jun 2012
    Posts
    44
    Thanks
    17
    Thanked 0 Times in 0 Posts
    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

  • #8
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,471
    Thanks
    6
    Thanked 980 Times in 953 Posts
    Quote Originally Posted by mwx6205 View Post
    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.

  • #9
    New Coder
    Join Date
    Jun 2012
    Posts
    44
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Hi VIPStephan,

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •