Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zh-CN]: add translation for Navigation.canGoBack #24523

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions files/zh-cn/web/api/navigation/cangoback/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: Navigation:canGoBack 属性
slug: Web/API/Navigation/canGoBack
l10n:
sourceCommit: ef75c1741b450c2331204be5563ee964ad5f4c48
---

{{APIRef("Navigation API")}}{{SeeCompatTable}}

{{domxref("Navigation")}} 接口的 **`canGoBack`** 只读属性在可以在导航历史记录中向后导航(即 {{domxref("Navigation.currentEntry", "currentEntry")}} 不是历史记录条目列表中的第一个)时返回 `true`,否则返回 `false`。

## 值

布尔值:如果可以在导航历史记录中向后导航,则为 `true`,否则为 `false`。

## 示例

```js
async function backHandler() {
if (navigation.canGoBack) {
await navigation.back().finished;
// 导航结束后处理任何必要的清理工作
} else {
displayBanner("你在第一页");
}
}

async function forwardHandler() {
if (navigation.canGoForward) {
await navigation.forward().finished;
// 导航结束后处理任何必要的清理工作
} else {
displayBanner("你在最后一页");
}
}
```

## 规范

{{Specifications}}

## 浏览器兼容性

{{Compat}}

## 参见

- [现代客户端路由:导航 API](https://developer.chrome.google.cn/docs/web-platform/navigation-api/)
- [导航 API 说明](https://github.com/WICG/navigation-api/blob/main/README.md)
- Domenic Denicola 的[导航 API 在线演示](https://gigantic-honored-octagon.glitch.me/)