简体   繁体   中英

Reload on click function not working in javascript

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM