url | The URL to open. |
Opens the URL specified, subject to the permissions and limitations of your app’s current platform and environment.
This is handled in different ways depending on the nature of the URL, and with different security restrictions, depending on the runtime platform.
Note: The OpenURL
method can be used to open more than just web pages; therefore, ensure that you're aware of the security implications involved before using this method.
This method is used to open HTTP (web page) URLs. If you provide a web page address as the parameter for this method, the web page opens in the default browser and display the browser application in the front.
In addition to the HTTP protocol used for web browsers, you can use other protocols in a URL, such as file transfer (FTP), email (mailto), database access (JDBC), and others platform-specific protocols. On some platforms, you can use OpenURL
to do different types of tasks in Unity.
The OpenURL
command is powerful and on some platforms, it can even open local files, run commands, and open connections over any protocol that the platform and security sandbox supports.
The OpenURL
method runs with the same permissions as your app itself. For example, if your app is running as a WebGL player in a desktop web browser, it cannot access local files on the machine, because the WebGL platform runs inside a security sandbox which prevents that.
However, this method is more powerful on platforms such as a desktop platform exe app, where it runs with fewer security restrictions without a security sandbox.
Important: Be cautious and do NOT pass a string to the OpenURL function to prevent any malicious attempts from third-party software.
On desktop platforms, you should consider this method to have similar security implications as an eval type function, which is present in most programming languages.
If your app uses OpenURL to open URL strings from a third-party, or the strings put together using any user-supplied data, then that data should be considered untrusted and used to run arbitrary code under the same permissions of your app.
You must also sanitise the untrusted data and validate to ensure that it generates the expected input for your application.
WebGL: From version 2019.4.25f1, 2020.3.5f1, 2021.1.2f1, and 2021.2.0a11, Application.OpenURL opens url in a new browser tab.
In previous versions,Application.OpenURL
opened url in the same browser tab, which terminates the active Unity application.
Android: Due to security changes in Android 7.0 (More information), Application.OpenURL
can no longer be used for opening local app files. To share files with other applications, you must use (FileProvider).
iOS: Application.OpenURL
cannot be used for opening local files.
Example:
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { void Start() { Application.OpenURL("http://unity3d.com/"); } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.