HarmonyOS web组件当h5使用 window.location.href =新地址时无法加载出来页面

HarmonyOS
2024-12-25 14:08:48
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zbw_apple

参考示例如下:

//Index.ets
import web_webview from '@ohos.web.webview';
@Entry
@Component
struct Index{
  @State message: string = 'Hello World';
  webviewController: web_webview.WebviewController = new web_webview.WebviewController();

  build() {
    RelativeContainer() {
      Web({ src: $rawfile("index.html"), controller: this.webviewController })
        .mixedMode(MixedMode.All)
        .javaScriptAccess(true)
        .domStorageAccess(true)
    }
    .height('100%')
    .width('100%')
  }
}

//index.html
<!DOCTYPE html>
  <head>
  <script>
  function test() {
    window.location.href = "https://www.w3schools.com"
  }
  </script>
  </head>
  <html>
  <body>
  <p>Hello World</p>
  <input type="button" value="Load new document" onclick="test()">
  </body>
  </html>
分享
微博
QQ
微信
回复
2024-12-25 17:14:15
相关问题
HarmonyOS Web组件加载在线H5页面
483浏览 • 1回复 待解决
HarmonyOS Web组件加载H5白屏
272浏览 • 1回复 待解决
HarmonyOS web组件加载h5h5拉起摄像头
866浏览 • 1回复 待解决
HarmonyOS web通过loadData加载h5标签
558浏览 • 1回复 待解决
Web组件h5页面如何交互?
505浏览 • 1回复 待解决
HarmonyOS Web组件加载本地H5文件跨域
382浏览 • 1回复 待解决
HarmonyOS h5 window.history 无效
227浏览 • 1回复 待解决