Reload on click function not working in javascript

允我心安 提交于 2021-01-07 03:58:08

问题


I have a button on my page that needs to reload on click and it's not doing so. https://codepen.io/JammyPiece/full/dBZaMP

It should also reload on click after the 'death screen' which explains how old the creature is when it died. I'm clicking and nothing happens.

I've read the w3 schools docs and read about the various ways to reload a screen. I can't see a difference between them and what I've done.


var c;


function myClock() {
   c=0;
    myTimer = setInterval(startUp, 60000);
    }


$(resetBtn).click(function(){
       refreshPage();
        myClock();
        living();
      });

function refreshPage(){
    window.location.reload();
}
function deathScreen(){

$(start).hide();
modal.style.display = "block";
$(dead).text(c);
clearInterval(myTimer);
$(ageing).text(0);

}
  // When the user clicks on <span> (x), close the modal

span.onclick = function() {
modal.style.display = "none";
refreshPage();
}

  // When the user clicks anywhere outside of the modal, close it

   window.onclick = function(event) {
if (event.target == modal) {
   modal.style.display = "none";
refreshPage();
}
}

I'm getting

Failed to load resource: the server responded with a status of 404 ()
pen.js:37 Uncaught (in promise) DOMException
pen.js:33 Uncaught TypeError: window.location.removedByCodePen is not a function
    at refreshPage (pen.js:33)
    at HTMLSpanElement.span.onclick (pen.js:241)
6pen.js:33 Uncaught TypeError: window.location.removedByCodePen is not a function
    at refreshPage (pen.js:33)
    at HTMLButtonElement.<anonymous> (pen.js:27)
    at HTMLButtonElement.dispatch (jquery-3.3.1.slim.min.js:2)
    at HTMLButtonElement.v.handle (jquery-3.3.1.slim.min.js:2)
dBZaMP:1 Refused to apply style from 'https://s.codepen.io/JammyPiece/fullpage/messaround.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

回答1:


I think CodePen Removed that function.

Use alternative method,

The parameter 0 indicates the number of steps to go back.

function refreshPage(){
    history.go(0);
}

OR

Use

function refreshPage(){
    window.location.href = window.location.href;
}

This will reset the location to the same. Page will refresh.



来源:https://stackoverflow.com/questions/56958553/reload-on-click-function-not-working-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!