www.webdeveloper.com
Results 1 to 4 of 4

Thread: how to refresh the current web page using javascript;

  1. #1
    Join Date
    Mar 2012
    Posts
    2

    how to refresh the current web page using javascript;

    Hi all,
    I used following method for refreshing current window/page but, i am getting error.
    chrome error:
    Uncaught TypeError: Object http://localhost:8033/eyePegasus/epm/importframes.jsf has no method 'refresh'

    fire fox error:
    Error: self.location.refresh is not a function
    Source File: http://localhost:8033/eyePegasus/epm/importframes.jsf
    Line: 73
    function handleMessage() {
    // alert("handle Message");
    self.location.refresh();
    //window.location.refresh();
    //location.refresh();
    // alert("handle Message");


    }

  2. #2
    Join Date
    Mar 2009
    Posts
    468
    Try 'reload()' instead of refresh.

  3. #3
    Join Date
    Mar 2012
    Posts
    2
    Quote Originally Posted by Tcobb View Post
    Try 'reload()' instead of refresh.
    I tried this but, i am facing problems .

    before reloading i am changing some check box status and selecting rows on table then i am using reload using javascript , it appearing like new page and tables rows are not selected and check box also.

    please help regarding how to reload page with out effecting previous changes.

  4. #4
    Join Date
    Mar 2009
    Posts
    468
    The following code should give you an idea of how to do this. The example uses localStorage, but you might want to use cookies instead. There may be errors in it--I didn't run it.

    First the HTML. Note the id and the event trigger.

    Code:
    <input type="checkbox" id = "c1" onchange="storeThis(this)">
    Now the storeThis function:

    Code:
    function storeThis(ref){  //writes the value of checked status to localStorage
      var val, id;            //where the id of the checkbox is the key
      id = ref.id;
      val = ref.checked;
      if(val){  //turn boolean value into a string--you can't store booleans in localStorage
          val='true';
      else{
         val = 'false';
          }
      localStorage.setItem(id, val);  //you might use a cookie for this instead
     }
    And finally something to be done upon reloading the page:

    Code:
    window.onload = function(){
      var x, val;
      val = localStorage.getItem('c1');  //see if an entry exists
      if(val !== null){ //if the entry exists...
        if(val == 'true'){  //convert string to boolean
           val = true;
        }
         else{
           val = false;
        }
        x = document.getElementById('c1');  //get the reference to the checkbox
        x.checked = val;  //set it to the recorded value
        }
    }

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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