提交 dc6bac76 编写于 作者: L lixiang

add Sample code for Customized UserAgent

Signed-off-by: Nlixiang <lixiang380@huawei.com>
上级 eeccf80a
......@@ -1992,6 +1992,37 @@ struct WebComponent {
}
```
支持开发者基于默认的UserAgent去定制UserAgent。
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController();
@State ua: string = ""
aboutToAppear():void {
web_webview.once('webInited', () => {
try {
// 应用侧用法示例,定制UserAgent。
this.ua = this.controller.getUserAgent() + 'xxx';
} catch(error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
}
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.userAgent(this.ua)
}
}
}
```
### getTitle
getTitle(): string
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册