url | 要打开的 URL。 |
遵循应用程序当前平台和环境的权限和限制,打开指定 URL。这采用不同方式进行处理(具体取决于 URL 的性质),并具有不同的安全限制(具体取决于运行时平台)。
Note: This method can be used to open more than just web pages; therefore, it has important security implications you must be aware of.
最常见的是,此方法用于打开 HTTP(网页)URL。如果提供网页地址作为此方法的参数,则网页会在默认浏览器中打开。它还会将浏览器应用程序带到前台。
As well as the HTTP protocol used for web page addresses, there are other types of protocols that you can use in a URL, such as file transfer (FTP), email (mailto), database access (JDBC), and others specific to certain platforms. On some platforms you can use OpenURL in Unity to do many different types of tasks.
For this reason, the OpenURL command can be unexpectedly powerful. On some platforms it can open local files, run commands, or 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 will not be able to access local files on the machine, because the WebGL platform itself runs inside a security sandbox which prevents that. If you are targeting other platforms such as standalone EXE app, your app runs with fewer security restrictions and no security sandbox, so this method is more powerful.
Important: You must be extremely careful that you do not provide a string to this function which could possibly be maliciously crafted or modified by a third party.
在独立平台上,应考虑此方法具有与 eval 类型函数(在许多其他编程语言中存在)相似的安全隐患。
If your app uses OpenURL to open URL strings which come from a third party, or which are put together using any user-supplied data, the user-supplied data should be considered untrusted and may be used to run arbitrary code under the same permissions of your app itself.
You must sanitise the untrusted data and validate that it is 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 opens url in the same browser tab, which terminates the running 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, you need to use FileProvider which allows you to share files with other applications.
iOS:Application.OpenURL 无法用于打开本地文件。
示例:
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.