www.webdeveloper.com
Results 1 to 2 of 2

Thread: history.go() question

  1. #1
    Join Date
    Jun 2008
    Posts
    136

    history.go() question

    Hello

    I'm testing things with javascript history.go() function. I'm getting different behavior from different browsers. I wanna know if there's a workout around this.

    history.go(-1) supposed to go back which does in all of the browsers but it doesn't show the data changed with js in most browsers. here's a sample code which works in ff but not ie or chrome:

    some page to go back to:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <body>
    <script type="text/javascript">
    
    function changeMe()
    {
    	div = document.createElement('div');
    	div.innerHTML = '<input id="something" type="text" name="something" />';
    	document.getElementById('change').appendChild(div);
    }
    
    </script>
    
    <div id="change"></div>
    
    <a href="javascript: void(0);" onclick="javascript: changeMe();">Add input</a>
    <a href="javascript: void(0);" onclick="document.getElementById('something').value = '12312313'">Put value in input</a>
    <a href="next.html">Goto next page</a>
    </body>
    </html>
    next.html just to redirect back:
    Code:
    <a href="Javascript: history.go(-1);">go back</a>
    Now when going back to the page with FF (also opera and safari), it shows both the inserted input AND the value we put in it. but with chrome and IE they do not show neither the inserted div and the value. In other words they won't show the changes js made to the page.

    I was wondering if it is possible to make them remember the changes that js made?

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Well, some browsers will load the previous page from cache, some will re-loaded it from server. It is up to the browser's type AND to the browser's settings.

    As a general rule, the javascript changes are lost when the session changes, because JavaScript is client-side language.

    To keep some changes you may have several solutions

    - a client-side (JavaScript) cookie
    - a server-side cookie or/and a server-side session
    - HTML5 local storage and/or web storage

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles