x


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.

more ▼

asked Dec 17 '11 at 11:29 PM

sanamdehghan gravatar image

sanamdehghan
46 14 21 23

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()).

Dec 18 '11 at 12:31 AM tomekkie2

Thanks for help. I try it. :)

Dec 18 '11 at 10:31 AM sanamdehghan

Possibly I commented wrong, I on writing "window", I meant just the browser tab.

Dec 18 '11 at 10:55 AM tomekkie2

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 :)

Dec 18 '11 at 11:08 AM sanamdehghan
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Dec 18 '11 at 12:16 AM

Bunny83 gravatar image

Bunny83
45.2k 11 49 207

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.

Dec 18 '11 at 10:32 AM sanamdehghan
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x126
x57

asked: Dec 17 '11 at 11:29 PM

Seen: 870 times

Last Updated: Dec 18 '11 at 03:18 PM