• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by sanamdehghan · Dec 17, 2011 at 11:29 PM · browserexit

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.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tomekkie2 · Dec 18, 2011 at 12:31 AM 0
Share

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

avatar image sanamdehghan · Dec 18, 2011 at 10:31 AM 0
Share

Thanks for help. I try it. :)

avatar image tomekkie2 · Dec 18, 2011 at 10:55 AM 0
Share

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

avatar image sanamdehghan · Dec 18, 2011 at 11:08 AM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sanamdehghan · Dec 18, 2011 at 10:32 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How would I go about getting the results of a javascript variable to a string inside script? 3 Answers

Receive UDP Messages in Browser plugin. 0 Answers

Web Player Crashes Window Instance 1 Answer

Browser to webplayer communication problem 0 Answers

Capturing sound input with low latency 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges