Skip to main content
1 of 3
Aristos
  • 66.6k
  • 16
  • 5

Reload current page example - not work here, for the moment.

function  ReloadPage()
{
    alert(top.location.href);
    top.location.replace( updateURLParameter(top.location.href, "_rnd", Math.random()) );
    return false;
}
//
// this function is an improved version of
// http://stackoverflow.com/a/10997390/159270
//
function updateURLParameter(url, param, paramVal)
{
    var TheAncor = null;
    var newAdditionalURL = "";
    var tempArray = url.split("?");
    var baseURL = tempArray[0];
    var additionalURL = tempArray[1];
    var temp = "";

    if (additionalURL) 
    {
        var tmpAncor = additionalURL.split("#");
        var TheParams = tmpAncor[0];
            TheAncor = tmpAncor[1];
        if(TheAncor)
            additionalURL = TheParams;

        tempArray = additionalURL.split("&");

        for (i=0; i<tempArray.length; i++)
        {
            if(tempArray[i].split('=')[0] != param)
            {
                newAdditionalURL += temp + tempArray[i];
                temp = "&";
            }
        }        
    }
    else
    {
        var tmpAncor = baseURL.split("#");
        var TheParams = tmpAncor[0];
            TheAncor  = tmpAncor[1];

        if(TheParams)
            baseURL = TheParams;
    }

    if(TheAncor)
        paramVal += "#" + TheAncor;

    var rows_txt = temp + "" + param + "=" + paramVal;
    return baseURL + "?" + newAdditionalURL + rows_txt;
}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

  
<a href="#" onclick="return ReloadPage();">reload page</a>

Aristos
  • 66.6k
  • 16
  • 5