Eel: Call window.close() on javascript with Eel

Created on 13 Oct 2019  路  6Comments  路  Source: ChrisKnott/Eel

Hi so I've been trying to close a window on javascript working with eel, but window.close() doesn't seem to work, are there any other ways to make the window close or to terminate the eel process on javascript?

help wanted

Most helpful comment

I was able to fix this issue with this window.open('','_self').close() code instead of the window.close() method.

All 6 comments

window.close() seems to work for me - can you share your code please? It's very difficult to help if I can't reproduce the problem, and having your exact code will generally help there. :)

@samuelhwilliams here :)

 <script>
      window.onload = function() {
        //when page loads execute this function
        swal({
          title: "Welcome",
          text: "You were successfully logged in!",
          icon: "success",
          button: "Thanks",
          closeOnClickOutside: false,
          closeOnEsc: false,
          closeOnEsc: false
        }).then(value => {
          //if button "ok" is clicked it returns true in the value variable and then closes the window if true
          console.log("closing");
          window.close();
        });
      };
    </script>

When clicking on the button, an error message is displayed on the console which is the following
Scripts may close only the windows that were opened by it., I tried opening the html page on chrome directly and window.close() works and closes my page when the swal button is clicked but whenever I open it with Eel with python main.py and I try to click on the button Thanks nothing happens and the previous error message appears in the console.

I was able to fix this issue with this window.open('','_self').close() code instead of the window.close() method.

Thanks for the response @FutureLights, I tried adding window.open('', '_self').close(); after then(value => { but I still get this error Scripts may close only the windows that were opened by it.

What browser are you using?

Found it so instead of redirecting with javascript to my page which I couldn't close later I created a js function that replaced the href and opened a new window so I could then call the window.close() argument. Here is my function if anyone wants to use it:

function Pospopup(URL, title) //?Function to open new window with same position of parent window
{
  let left = window.screenX; //takes left property of mainfile window
  let top = window.screenY; //takes left property of mainfile window
  window.open(URL, title, "width=800, height=600, top=" + top + ", left=" + left); //opens new window and sets the left and top property
}

the left and top var are just to keep the window in the same position as the previous one.
Anyway big thanks to @samuelhwilliams and @FutureLights for helping me out

Was this page helpful?
0 / 5 - 0 ratings

Related issues

04fsnape picture 04fsnape  路  4Comments

jerearaujo03 picture jerearaujo03  路  3Comments

andrewtquick picture andrewtquick  路  4Comments

HorrifyingMonkey picture HorrifyingMonkey  路  4Comments

Swicegood picture Swicegood  路  4Comments