I’m making an online game. I want to have a quit button on the main menu so that if the player clicks it the browser window be closed. Could you please help me and give the code for it?
I used this one, but it didn’t do anything.
var isQuitButton = false;
function OnMouseUp()
{
if(isQuitButton)
{
Application.Quit();
}
…
}
Thanks for help.
I think you should be able to do that this way on most browsers provided that the window you run the webplayer has been opened by javascript. In other words I thik you need the starting page which opens with js the page with the webPlayer on it, an then you should be able to close that window with Application.ExternalEval(window.close()).
thanks a lot, I replace the code above with Application.ExternalEval("window.close()"); and it just closed the tab that game was playing on it. thanks again :)
That can’t be enforced by the UnityWebplayer. Usually people uses tabs nowadays, so closing a window without permission is something which lays outside of what the webplayer should be able to do.
However, if the user allows a webpage to close a window via javascript you can do it that way. Take a look at Application.ExternalEval and for more information on window.close see this page
Well I think I asked it wrong, I don't want my game to close the browser with its all open tabs, just closing the tab which the game is playing on is enough for me.
I think you should be able to do that this way on most browsers provided that the window you run the webplayer has been opened by javascript. In other words I thik you need the starting page which opens with js the page with the webPlayer on it, an then you should be able to close that window with Application.ExternalEval(window.close()).
– tomekkie2Thanks for help. I try it. :)
– anon16049781Possibly I commented wrong, I on writing "window", I meant just the browser tab.
– tomekkie2thanks a lot, I replace the code above with Application.ExternalEval("window.close()"); and it just closed the tab that game was playing on it. thanks again :)
– anon16049781