Skip to main content
2 of 3
added 273 characters in body
Aristos
  • 66.6k
  • 16
  • 5

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

Error Message:

Uncaught SecurityError: Sandbox access violation: Blocked a frame at "http://stacksnippets.net" from accessing a frame at "http://meta.stackoverflow.com". The frame requesting access is sandboxed and lacks the "allow-same-origin" flag.

// function  ReloadPage()
//{
    console.log(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