Search code examples
javascripthtmlphonegap

How to close html file javascript


I'm opening a new html file on button press using this:

window.location = "menu.html";

I want to go back to the index.html file in my "menu" activity after a button press. I tried using

window.location = "index.html";

But it creates a new screen and if I click the return buton to go to my homepage it returns to the previous activities. Also

    window.opener.location = '/redirect.html';
    window.close();

Doesn't work. So how do I close the menu activity to go back to my main activity.

PS: should I use window.location or window.location.href to open new html file

Thanks in advance!


Solution

  • I fixed it using

        history.go(-1);
        navigator.app.backHistory();
    

    sugested in this answer: Phonegap - navigator.app.backHistory() not working on HTML back button

    Also the href on the end of window.location.href is used for links so you should use just window.location