> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/jiao-hu-xing/external-links.md).

# 外部链接

链接到其他场景或外部网站

你可以从你的场景添加链接到其他内容，既可以链接到其他场景，也可以链接到外部网站。

## 在 Creator Hub 中使用 Scene Editor

添加外部链接或传送点最简单的方法是使用场景编辑器。使用 **传送** [智能物品](/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/smart-items.md) 来添加到 Genesis City 中另一个场景的传送，或使用任何 **社交链接** 智能物品来添加指向外部网站的链接。

![](https://2460066822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-be65d3e84db80b872ee31e90d17c016a7b520fbc%2Fsocial-links.png?alt=media\&token=aae35e9f-eaa6-42ad-ac88-ae670c9b849a)

## 传送点

要将玩家传送到另一个场景，请调用下面的函数，并指定你希望玩家传送到的坐标。

```ts
import { teleportTo } from "~system/RestrictedActions"

(...)

teleportTo({ worldCoordinates: { x: -51, y: 1 } })
```

在玩家被传送前，会向他们显示一个确认界面，该界面展示目标场景的 `scene.json 文件`，包括场景 `name`, `描述` 和 `navmapThumbnail`。参见 [场景元数据](/creator/content-creator-zh/chang-jing-sdk7/xiang-mu-lei-xing/scene-metadata.md) ，有关如何设置这些数据的详细信息。

请注意，传送会把你带到指定坐标的某个场景，但不一定是那些相同的坐标。这意味着，当前往一个包含多个地块的场景时，玩家可能不会落在指定的相同坐标处，而是会落在该场景创作者指定的某个生成点之一。

要将玩家移动到当前场景内的另一组坐标，请使用 `movePlayerTo()` 函数代替。详见 [移动玩家](/creator/content-creator-zh/chang-jing-sdk7/jiao-hu-xing/tou-xiang/move-player.md).

## 传送到 WORLD

要将玩家发送到一个未发布在公开 Genesis City 地图上的场景，而是发送到一个独立的 [Decentraland WORLD](/creator/content-creator-zh/chang-jing-sdk7/fa-bu/publishing-options.md#decentraland-worlds)，请传入一个 `realm` 为 `teleportTo()`.

```ts
import { teleportTo } from "~system/RestrictedActions"

(...)

teleportTo({ realm: 'mannakia.dcl.eth' })
```

`realm` 可以接受世界名称，例如 `mannakia.dcl.eth`，或者一个 realm URL。

没有 `worldCoordinates`，玩家会落在目标地点的某个生成点上。添加坐标可选择该世界中的特定地块：

```ts
// 降落到某个特定世界中的 12,34 地块
teleportTo({
	realm: 'mannakia.dcl.eth',
	worldCoordinates: { x: 12, y: 34 },
})
```

在玩家更改 realm 之前，会向他们显示一个确认界面。它会询问 *“你确定要进入这个 World 吗？”* 并显示目标（世界名称，或 realm URL 的主机名）。只有当玩家接受时才会移动。

要从一个 world 将玩家送回 Genesis City，不要包含 `realm` 字段，默认值为 Genesis City。

{% hint style="warning" %}
**📔 注意**：该 `realm` 字段需要 `@dcl/sdk` 7.28.0 或更新版本。
{% endhint %}

### changeRealm 已弃用

较旧的场景使用 `changeRealm()` 来进入一个 world。它仍然有效，但请改用 `teleportTo({ realm })` 。 `changeRealm()` 还会显示一个确认界面；其可选的 `message` 字段只会替换默认提示文本。

`changeRealm()` 会在玩家接受提示后立即解析，而不是等到新 realm 实际上线时。A `teleportTo()` 之后的调用会针对 **旧** realm 运行，并把玩家送到错误的位置。 `teleportTo({ realm })` 会在一次调用中完成这两个步骤，因此不会存在这个间隙。

## 外部链接

要添加到外部网站的链接，请使用 `openExternalUrl()` 命令。

```ts
import { openExternalUrl } from '~system/RestrictedActions'

openExternalUrl({ url: 'google.com' })
```

为了防止滥用此功能向玩家发送垃圾信息，只能通过实体上的显式点击或按钮事件来调用 `openExternalUrl` 。不能因为计时器、碰撞区域或全局点击事件而调用此函数。有关如何执行此操作的详细信息，请参见 [按钮事件](/creator/content-creator-zh/chang-jing-sdk7/jiao-hu-xing/an-niu-shi-jian/click-events.md) 。

当 `openExternalUrl` 被调用时，玩家会看到一个确认界面，告知他们链接将带他们去哪里，并可接受或拒绝访问该链接。

该链接会在新标签页中打开，同时保留 Decentraland 中的原始标签页。

如果玩家勾选 *信任此域名* 复选框，只要链接来自同一场景且指向同一域名，他们在本会话期间就不会再次被提示。

## 复制到剪贴板

要将字符串复制到玩家的剪贴板，请使用 `copyToClipboard()`。之后，当玩家在 Decentraland 聊天或其机器上的任何其他应用中进行 *粘贴* 时，他们粘贴的将是你的字符串。

```ts
import { copyToClipboard } from "~system/RestrictedActions"

copyToClipboard( { text: 'My text to copy' } )
```


---

# 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://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/jiao-hu-xing/external-links.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.
