Skip to content Skip to sidebar Skip to footer

Refresh Page On Button Click And After That Call An Function

I am trying to refresh an web page on button click and after page refresh call an function. But its reverse is not happening i.e. first call the function and after that refresh the

Solution 1:

use below code

<body onload="onrefresh();">

<a href="javascript:myfun();">

function myfun(){
    window.location.search += '&reload=true';
}
function onrefresh(){
 if(gup("reload")=='true'){
    // DO whatever want to do. 
  }
}


function gup( name ){
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
    var regexS = "[\\?&]"+name+"=([^&#]*)";  
    var regex = new RegExp( regexS );  
    var results = regex.exec( window.location.href ); 
    if( results == null )
        return "";  
    else
      return results[1];
}

Solution 2:

<a href="javascript:abc();"><script>function restartall() {
    $('#text').append('hello');
}

function abc() {
    document.location.reload();
    restartall();

}</script>

Solution 3:

When you reload page you're loosing JavaScript call stack. You would have to append some parameter to URL or use cookie.


Solution 4:

try this

<script>
    function restartall(){
        $('#text').append('hello');
        document.location.reload();
    }
</script>

<input type="button" onclick="restartall()" value="Referash Map" />
<div id="text"></div>

Post a Comment for "Refresh Page On Button Click And After That Call An Function"