lundi 29 juin 2015

How do I call a function when going back to a page with javascript?

So I'm having problems trying to figure out how to call a function when I am going back to a page, maybe you guys can help me. In my bossHandler file I have it for when the boss's HP reaches 0, it calls back to my storyPage.html file and continues where the story left off. This is what I have.

bossHandler.js

if(currMonster.currHp <= 0) {
    currMonster.currHp = 0;
    alert("You have killed " + currMonster.name + "! \n You gained " + currMonster.gold + " gold!!!")
    myChar.gold += currMonster.gold;
    updateCookie(myChar);
    loadPageWithNumber(17);
}

On my storyPage.js I have

function loadPageWithNumber(pageNumber){
    window.location ="storyPage.html";
    nextStoryText(pageNumber);
}

but the problem I am getting is that it is calling nextStoryText() before the new page has loaded. I've tried a few things and also tried changing the page back in the if statment and then calling nextStoryText() from my bossHandler.js file and that still didn't work. Tried looking around on here for a solution but I kept finding ways to just go back to the page and call an onload event, but I don't want a event to fire every time I load that page. Is there a easy way to do this?

Also, my storyPage.html is the first page I'm on until an encounter starts, then it heads to my bossPage.html. Once the boss is dead I want to go BACK to storyPage.html and that's the problem I'm having currently.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire