Jammy Piece
Jammy Piece

Reputation: 25

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.

Upvotes: 2

Views: 2152

Answers (2)

satishT
satishT

Reputation: 1

After research I got solution for "removedByCodePen" function and Tested on this Blogger blog

Just replace

window.location.removedByCodePen();

To Use history as alternative method,

window.history.go(0);

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

Upvotes: 0

BadPiggie
BadPiggie

Reputation: 6359

I think CodePen removed that function.

Use history as 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.

Upvotes: 5

Related Questions