> For the complete documentation index, see [llms.txt](https://developers-apps-in-toss.toss.im/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/common/screen/open-url.md). Agents can also search and read this documentation through its [MCP server](https://developers-apps-in-toss.toss.im/~gitbook/mcp).

# 打开外部 URL

`openURL` 这个函数是一个实用工具，允许你在设备的默认浏览器或已连接的应用中打开指定的 URL。这个函数会在内部使用 React Native 的 [`Linking.openURL`](https://reactnative.dev/docs/0.72/linking#openurl)。

**签名**

```typescript
function openURL(url: string): Promise<any>;
```

**参数**

* **url** · 必填 · `string`

  要打开的外部网页地址或深度链接路径。

**返回值**

* `Promise<any>`

  返回一个在 URL 成功打开时 resolve 的 Promise。

**示例**

**打开外部网站**

{% tabs %}
{% tab title="tsx\[React]" %}

```tsx[react]
import { openURL } from '@apps-in-toss/web-framework';

function Page() {
  const handlePress = () => {
    openURL('https://google.com');
  };

  return (
    <button onClick={handlePress}>
      打开谷歌网站
    </button>
  );
}
```

{% endtab %}

{% tab title="React Native" %}

```tsx
import { openURL } from '@granite-js/react-native';
import { Button } from 'react-native';

function Page() {
  const handlePress = () => {
    openURL('https://google.com');
  };

  return <Button title="打开谷歌网站" onPress={handlePress} />;
}
```

{% endtab %}
{% endtabs %}

**打开深度链接**

{% tabs %}
{% tab title="tsx\[React]" %}

```tsx[react]
import { openURL } from '@apps-in-toss/web-framework';

openURL('intoss://{appName}');
```

{% endtab %}

{% tab title="React Native" %}

```tsx
import { openURL } from '@granite-js/react-native';

openURL('intoss://{appName}');
```

{% endtab %}
{% endtabs %}

### 参考事项

* 如果无法打开外部 URL（如协议错误、网络被阻断等），Promise 可能会被 reject。
* 在 WebView 环境中会新开浏览器标签页，而在默认应用中则会切换到外部应用或浏览器。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/common/screen/open-url.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
