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

# 打开外部 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 时（例如无效的 scheme、网络被阻止等），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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
