javascriptjquerycodepen

How to reload a web page on CodePen full page view by clicking a button


$("#quoteButton").on("click", function() {
    location.reload();
});

I worked on a 'Random Quote Machine' from Free Code Camp web site via NetBeans IDE 8.2 and this code works well, but when I paste it on CodePen for some reason it doesn't work on CodePen full page view. Is there a way that I can make a page reload when I click on a button on CodePen full page view anyway?

In Debug mode view on CodePen it's working. Here's a link to my CodePen: https://codepen.io/NemStep/pen/pdmowz


Solution

  • This is an alternative to location.reload.

    The parameter of go is the page index, in this case, 0 is the current page.
    For instance, go(-2) would go 2 pages back in the history.

    $("#quoteButton").on("click", function() {
        history.go(0);
    });