Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Closing a tab through code when published on web

Discussion in 'Scripting' started by Carling_Technologies, Jul 20, 2016.

  1. Carling_Technologies

    Carling_Technologies

    Joined:
    Jul 20, 2016
    Posts:
    33
    *New to forums, I apologize in advance if this topic already exists*

    I am trying to publish a game (in development) and I'm having trouble creating the quit or openurl buttons. It was originally going to be published on Mac, Windows, and Linux but will now be on web player or opengl. I have tried using Application.ExternalCall("window.close()"); for the quit button but to no avail does it work.

    What code allows me to close the tab or quit the game when hosted on a site? Am I missing something else?
    Will be posted on sites such as:
    • itch.io
    • madewithunity.com
    • kongregate.com
     
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    First of all, webplayer will be obsolate soon I believe
    You can't close a browser tab by choice (except for some javascript trickery, but let's not talk about that). Browsers are strictly enforcing rules on applications on what can or cannot be done. But you could always crash the whole browser (or the tab in the case of chrome) by running a while(true) loop which is always fun :p
     
  3. Carling_Technologies

    Carling_Technologies

    Joined:
    Jul 20, 2016
    Posts:
    33
    So essentially you're saying that it's practically impossible to do from a browser? Is there any sort of substitute I can do for a quit button that doesn't involve crashing? Like instead of closing the tab can I close the Unity "window" in the browser? And what about the openurl button?

    Thanks for the reply, Jon :)
     
  4. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    It would seem really weird, I wouldn't do it, if someone wants to quit, they usually close the tab
    Maybe (just maybe) you could do a go back to the previous page, but I don't know about that
     
  5. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,139
    I assume you're doing webGL, but if you're not, webplayer is pretty much only supported on firefox now (maybe safari) and even that will be gone soon.

    However, I'm not sure why you're trying to force close a tab. It'd be better to give the player a reason to close. Simply give them a game over screen.
     
  6. Carling_Technologies

    Carling_Technologies

    Joined:
    Jul 20, 2016
    Posts:
    33
    I suppose the best thing I could do is bring them back to the main menu, thanks for the assistance guys I appreciate it!

    Jon