Rock Paper Scissors - running code after redirect

I have most things working but I’m stumped with a single issue. I have two pages, index.html and winner.html. After the game completes on index.html, function “redirect” gets triggered and redirects to winner.html. This works fine. At that time, my code seems to stop running even though a new function should be called with a simple console.log. I am using the same scripts.js on each html and it’s located in the header. I’ve tried moving it to the end of the body with no change. I know it is still linked on winner.html because a button on that page has an onclick to reset the game and redirect back to index.html (which works fine).

Here is the snippet:

// game ends, redirect page to end game   
function redirect() {
    window.location = "winner.html";
    gameEnds();
};

// declare winner
function gameEnds(winner) {
    console.log("Success");
};

// click button reloads index.html to play again
function reset() {
    window.location = "index.html";

I would have expected redirect() to change the page and then call gameEnds() but it doesn’t. I’m at a loss and Google hasn’t been much help. Any ideas?

Thanks.

I found out that having a seperate page is probably not the most ideal solution, and the code “reruns” with the refresh of a page or the loading of a new page. Instead, I learned about hiding/revealing elements and used that to essentially hide the whole page, then show the winner and reset button. There might still be a better solution out there but this one feels cleaner and I’m happy with it for now.