- Home /
Closing a browser
Hi.
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()).
Possibly I commented wrong, I on writing "window", I meant just the browser tab.
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 :)
Answer by Bunny83 · Dec 18, 2011 at 12:16 AM
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.
Your answer
Follow this Question
Related Questions
Link to another browser tab 0 Answers
Which broswer is best for running Unity? 2 Answers
Unity3d + Android Webkit/Webview 1 Answer
Can't load external XML in browser 1 Answer
Click on revmob redirected 0 Answers