Search code examples
javascriptgoogle-chrome-app

chrome.app.window.create creates two windows


After digging around trying to figure out how to open multiple HTML files in a Chrome App, I came across this as a solution. This solution opens a new window instead of it being in one window.

But for some reason, it's opening up two windows at the same time when I press my button hyperlink. And I do not know where in the code this is causing the problem.

So here's the important piece of the software: (script.js)

document.querySelector('#startButton').addEventListener('click', function () {
    chrome.app.window.create('index.html', { "width": 400, "height": 500 });
    window.close();
});

And here's the button:

<button onclick="window.location.href='index.html'" id="startButton">Let's Go!</button>

window.close() just closes the previous window, so it has nothing to do with that.

Screenshot: http://ibb.co/kYJQGv

My Git repo will give you what I haven't provided (under MineKart_desktop folder): https://github.com/Mr-El/MineKart


Solution

  • On your button, you have two firing functions:

    1. onclick attribute which opens the window 'index.html'

    2. eventlistener to create a new window 'index.html'

    Remove the onclick attribute from the button and see what happens!