未验证 提交 e8ad8c47 编写于 作者: O openharmony_ci 提交者: Gitee

!7570 更新ts-basic-components-web.md,新增onContextMenuShow

Merge pull request !7570 from 虞仕浩/master
......@@ -1211,6 +1211,7 @@ onHttpAuthRequest(callback: (event?: { handler: HttpAuthHandler, host: string, r
})
return true;
})
}
}
}
```
......@@ -1250,6 +1251,46 @@ onPermissionRequest(callback: (event?: { request: PermissionRequest }) => void)
}
})
})
}
}
}
```
### onContextMenuShow<sup>9+</sup>
onContextMenuShow(callback: (event?: { param: WebContextMenuParam, result: WebContextMenuResult }) => boolean)
长按特定元素(例如图片,链接),跳出菜单。
**参数:**
| 参数名 | 参数类型 | 参数描述 |
| ------- | ------------------------------------ | ---------------- |
| param | [WebContextMenuParam](#webcontextmenuparam9) | 菜单相关参数。 |
| result | [WebContextMenuResult](#webcontextmenuresult9) | 菜单相应事件传入内核。 |
**返回值:**
| 类型 | 说明 |
| ------ | -------------------- |
| boolean | 自定义菜单返回true,默认菜单返回false。 |
**示例:**
```ts
// xxx.ets
@Entry
@Component
struct WebComponent {
controller:WebController = new WebController();
build() {
Column() {
Web({ src:'www.example.com', controller:this.controller })
.onContextMenuShow((event) => {
console.info("x coord = " + event.param.x());
console.info("link url = " + event.param.getLinkUrl());
})
}
}
}
```
......@@ -1708,6 +1749,98 @@ grant(resources: Array\<string\>): void
| --------- | --------------- | ---- | ----- | ---------------------- |
| resources | Array\<string\> | 是 | - | 网页所请求的权限资源列表。|
## WebContextMenuParam<sup>9+</sup>
实现长按页面元素跳出来的菜单信息。示例代码参考[onContextMenuShow事件](#oncontextmenushow9)
### x<sup>9+</sup>
x(): number
弹出菜单的x坐标。
**返回值:**
| 类型 | 说明 |
| --------------- | ----------------------- |
| number | 显示正常返回非负整数,否则返回-1。 |
### y<sup>9+</sup>
y(): number
弹出菜单的y坐标。
**返回值:**
| 类型 | 说明 |
| --------------- | ----------------------- |
| number | 显示正常返回非负整数,否则返回-1。 |
### getLinkUrl<sup>9+</sup>
getLinkUrl(): string
获取链接地址。
**返回值:**
| 类型 | 说明 |
| --------------- | ----------------------- |
| string | 如果长按位置是链接,返回经过安全检查的url链接。 |
### getUnfilterendLinkUrl<sup>9+</sup>
getUnfilterendLinkUrl(): string
获取链接地址。
**返回值:**
| 类型 | 说明 |
| --------------- | ----------------------- |
| string | 如果长按位置是链接,返回原始的url链接。 |
### getSourceUrl<sup>9+</sup>
getSourceUrl(): string
获取sourceUrl链接。
**返回值:**
| 类型 | 说明 |
| --------------- | ----------------------- |
| string | 如果选中的元素有src属性,返回src的url。 |
### existsImageContents<sup>9+</sup>
existsImageContents(): boolean
是否存在图像内容。
**返回值:**
| 类型 | 说明 |
| --------------- | ----------------------- |
| boolean | 长按位置中有图片返回true,否则返回false。 |
## WebContextMenuResult<sup>9+</sup>
实现长按页面元素跳出来的菜单所执行的响应事件。示例代码参考[onContextMenuShow事件](#oncontextmenushow9)
### closeContextMenu<sup>9+</sup>
closeContextMenu(): void
不执行WebContextMenuResult其他接口操作时,需要调用此接口关闭菜单。
### copyImage<sup>9+</sup>
copyImage(): void
WebContextMenuParam有图片内容则复制图片。
## WebController
通过WebController可以控制Web组件各种行为。一个WebController对象只能控制一个Web组件,且必须在Web组件和WebController绑定后,才能调用WebController上的方法。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册