HarmonyOS 鸿蒙Next 应该在什么阶段设置web的useragent 是否有示例代码
HarmonyOS 鸿蒙Next 应该在什么阶段设置web的useragent 是否有示例代码
应该在什么阶段设置web的useragent 是否有示例代码
2 回复
设置useragent可以在web的onControllerAttached中进行设置
import web_webview from '@ohos.web.webview';
[@Entry](/user/Entry)
[@Component](/user/Component)
struct VideoDemo {
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Web({ src: $rawfile('web.html'),controller:this.controller })
.onControllerAttached(()=>{
let userAgent = this.controller.getUserAgent();
this.controller.setCustomUserAgent(userAgent);
})
}
}
}
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>