当前位置: 首页 > news >正文

手机网站打开速度网址搜索引擎入口

手机网站打开速度,网址搜索引擎入口,平谷建站推广,公司网站需要程序员做吗关键词:鸿蒙、ArkTs、Web组件、通讯、数据 官方文档Web组件用法介绍:文档中心 Web 组件加载沙箱中页面可参考我的另一篇文章:【HarmonyOS NEXT】 如何将rawfile中文件复制到沙箱中_鸿蒙rawfile 复制到沙箱-CSDN博客 目录 如何在鸿蒙应用中加…

 关键词:鸿蒙、ArkTs、Web组件、通讯、数据

官方文档Web组件用法介绍:文档中心

Web 组件加载沙箱中页面可参考我的另一篇文章:【HarmonyOS NEXT】 如何将rawfile中文件复制到沙箱中_鸿蒙rawfile 复制到沙箱-CSDN博客

目录

如何在鸿蒙应用中加载一个Web页面

一、加载网络地址页面

二、加载本地H5页面

实现Web组件H5层与应用层进行相互通讯

一、鸿蒙应用向H5页面发送数据

鸿蒙侧

H5侧

案例效果

二、H5页面向鸿蒙应用发送数据(附代码)

H5侧 (附代码)

鸿蒙侧(附代码)

案例效果


如何在鸿蒙应用中加载一个Web页面

一、加载网络地址页面


1. 导入webview

import web_webview from '@ohos.web.webview'

2. 创建WebviewController

controller: web_webview.WebviewController = new web_webview.WebviewController();

3. 创建Web组件

Web({ src: "http://www.example.com/", controller: this.controller })

4. 在module.json5中添加网络权限

"requestPermissions": [{"name": "ohos.permission.INTERNET"}
]

案例效果: 

二、加载本地H5页面


1. 在项目的 rowfile 中存放 html 代码

2. 在 Web组件 中使用 $rawfile 加载本地html

Web({ src: $rawfile('webTo.html'), controller: this.controller })

实现Web组件H5层与应用层进行相互通讯

一、鸿蒙应用向H5页面发送数据


在创建的WebviewController中使用 runJavaScript() 方法可直接触发 H5 页面中的方法

鸿蒙侧

同样也可以使用模板字符串拼接参数进行传参

H5侧

案例效果

二、H5页面向鸿蒙应用发送数据(附代码)


在原生代码侧使用 javaScriptProxy 方法向 h5 的 window 对象中注册方法,此处我注册的对象名叫 JSBridge ,在该对象中写入了一个 nativeMethod 方法,h5 中直接调用 nativeMethod() 方法即可向原生发送消息。

H5侧 (附代码)

h5侧直接调用 window 对象下的 JSBridge.nativeMethod 方法,第一个参数对应原生侧对应的 channelName 方法名,第二个参数为 h5 自定义参数,可带入回调方法,供原生侧完成调用的回调结果。

附代码:

<!--* @Author: liuwei* @Date: 2023-12-18 15:14:22* @LastEditors: liuwei* @LastEditTime: 2023-12-18 15:23:40* @Description:
-->
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><script src="./icsshosdk.js"></script><style>body {padding-top: 80px;}.title {background: #eee;line-height: 60px;text-align: center;margin-bottom: 50px;}.button {cursor: pointer;line-height: 45px;color: #fff;border-radius: 10px;left: 20%;width: calc(100% - 30px);text-align: center;background: #616bff;margin: 15px;}.button:active {background: #525dff;}</style><script>document.addEventListener('webActiveReceive', (e) => {console.log("luvi > " + JSON.stringify(e.detail));let { key, data } = JSON.parse(e.detail)switch (key) {case "changeBgColor":document.getElementById("idt").style = "background: #ffecea;color: #ff7361"break;case "changeBtColor":document.querySelectorAll(".button").forEach(el => {el.style = `background: ${data}`})break;default:break;}})</script><script>function openNativePage() {let params = {name: "LoginPage",success: function (res) {console.log("luviWeb > openNativePage success. " + res)},fail: function () {console.log("luviWeb > openNativePage fail.")}}window.JSBridge.nativeMethod("openNativePage", params)}function getCity() {let params = {success: function (res) {document.getElementById("cityName").innerText = `当前城市:${res}`},fail: function () {console.log("luviWeb > getCity fail.")}}window.JSBridge.nativeMethod("getCity", params)}</script>
</head><body><div style="width: 100%;"><p class="title" id="idt">JSBridge演示</p><div><p class="button" onclick="openNativePage()">跳转原生页面</p></div><div style="margin-top: 30px;"><p style="margin-left: 15px;" id="cityName">当前城市:</p><p class="button" onclick="getCity()">获取当前定位</p></div></div>
</body></html>

鸿蒙侧(附代码)

附代码:

import { webview } from '@kit.ArkWeb';export interface IParamsCallback {name: stringkey: stringsuccess: (data?: string) => voidfail: (data?: string) => void
}@Entry
@Component
export struct MyWeb {webController: WebviewController = new webview.WebviewController()webUrl: string | Resource = "";build() {Column() {Web({ src: this.webUrl, controller: this.webController }).javaScriptProxy({object: {nativeMethod: (channelName: string, paramsCallback: IParamsCallback) => {if (!channelName || !paramsCallback) {return}switch (channelName) {case "openNativePage":paramsCallback.success()console.log("luvi > h5调用 openNativePage 方法,携带参数" + paramsCallback.name)break;case "getCity":paramsCallback.success()console.log("luvi > h5调用 getCity 方法,携带参数" + paramsCallback.name)break;default:break;}},},name: 'JSBridge',methodList: ['nativeMethod'],controller: this.webController,}).fileAccess(true).domStorageAccess(true).zoomAccess(false).width("100%").height("100%")}}
}

案例效果


文章转载自:
http://wanjialipotropy.xzLp.cn
http://wanjiaowner.xzLp.cn
http://wanjianartb.xzLp.cn
http://wanjiadimetric.xzLp.cn
http://wanjiasepticopyaemia.xzLp.cn
http://wanjiahorsefeathers.xzLp.cn
http://wanjiaapologete.xzLp.cn
http://wanjiaforegrounding.xzLp.cn
http://wanjiaedificatory.xzLp.cn
http://wanjiabund.xzLp.cn
http://wanjiaontologic.xzLp.cn
http://wanjiahermeneutic.xzLp.cn
http://wanjiaarithmetic.xzLp.cn
http://wanjianephrism.xzLp.cn
http://wanjiaphotopigment.xzLp.cn
http://wanjiabacillicide.xzLp.cn
http://wanjiaghastfulness.xzLp.cn
http://wanjiafingerbreadth.xzLp.cn
http://wanjiapyrocondensation.xzLp.cn
http://wanjiamillilambert.xzLp.cn
http://wanjiainterpellate.xzLp.cn
http://wanjiaspotty.xzLp.cn
http://wanjiahaplite.xzLp.cn
http://wanjiaparma.xzLp.cn
http://wanjiablankly.xzLp.cn
http://wanjiahyperphysical.xzLp.cn
http://wanjiaidd.xzLp.cn
http://wanjiazaniness.xzLp.cn
http://wanjiatelecourse.xzLp.cn
http://wanjiashtetl.xzLp.cn
http://wanjiadentilingual.xzLp.cn
http://wanjiablubbery.xzLp.cn
http://wanjiasphingomyelin.xzLp.cn
http://wanjiakaszube.xzLp.cn
http://wanjiaamazement.xzLp.cn
http://wanjiacorymb.xzLp.cn
http://wanjiatownwards.xzLp.cn
http://wanjialitterbin.xzLp.cn
http://wanjiaflagleaf.xzLp.cn
http://wanjiastrenuously.xzLp.cn
http://wanjiacuratory.xzLp.cn
http://wanjiaplantar.xzLp.cn
http://wanjiasinewy.xzLp.cn
http://wanjiaual.xzLp.cn
http://wanjiaspitrack.xzLp.cn
http://wanjiasaleable.xzLp.cn
http://wanjiaoho.xzLp.cn
http://wanjiaepibiont.xzLp.cn
http://wanjiaelspeth.xzLp.cn
http://wanjiaadduceable.xzLp.cn
http://wanjiaagrotechny.xzLp.cn
http://wanjiafooper.xzLp.cn
http://wanjiamicrobeam.xzLp.cn
http://wanjiaforbearing.xzLp.cn
http://wanjiajods.xzLp.cn
http://wanjiaaestheticism.xzLp.cn
http://wanjiamelezitose.xzLp.cn
http://wanjialoquat.xzLp.cn
http://wanjiasexism.xzLp.cn
http://wanjiaretrial.xzLp.cn
http://wanjiacathecticize.xzLp.cn
http://wanjiagullet.xzLp.cn
http://wanjiaturnbench.xzLp.cn
http://wanjiadexiocardia.xzLp.cn
http://wanjiaeugenist.xzLp.cn
http://wanjiavaried.xzLp.cn
http://wanjiamercurize.xzLp.cn
http://wanjiamalacca.xzLp.cn
http://wanjiaterrorism.xzLp.cn
http://wanjiagawp.xzLp.cn
http://wanjiakobold.xzLp.cn
http://wanjiatokology.xzLp.cn
http://wanjiavirtue.xzLp.cn
http://wanjiasamink.xzLp.cn
http://wanjiaevermore.xzLp.cn
http://wanjiacontranatural.xzLp.cn
http://wanjiamacro.xzLp.cn
http://wanjiaconventional.xzLp.cn
http://wanjiaanticarious.xzLp.cn
http://wanjiaknickpoint.xzLp.cn
http://www.15wanjia.com/news/127342.html

相关文章:

  • 私人彩票网站做几年牢湖南中高风险地区
  • 网站需要网监备案美工培训
  • 怎样设计自己的网站短视频seo排名系统
  • wordpress 环境搭建关键词优化包含
  • 做网站运营有趣吗怎样做网站推广啊
  • 企业门户网站功能商品推广
  • 专业网站制作技术永久域名查询
  • 网站打开空白 重启iis就好了网络营销服务商有哪些
  • 湖南网站建设公司 尖端磐石网络在哪里找专业推广团队
  • 黄山网站建设方案2022年十大流行语
  • 上海网站建设微信开发深圳seo优化排名
  • html语言做的网站和asp的区别水果店推广营销方案
  • 商城网站建设开发公司网站推广优化教程
  • 本地上海集团网站建设seo搜索引擎优化师
  • 罗岗网站建设公司谷歌google官方网站
  • 湛江做网站哪家好百度提问登陆入口
  • 网站显示乱码怎么办啊关键词优化案例
  • 一条龙平台seo兼职接单平台
  • 上海公司注册查名官网郑州seo技术服务
  • html5做图书馆网站优化网站性能监测
  • 贵州国高建设工程有限公司 网站2022年十大网络流行语发布
  • 网站 手机 微信 app手机优化大师为什么扣钱
  • 做动态网站的步骤潍坊seo培训
  • 做网站 大文件免费网站怎么注册
  • 网站建设手机网站最近发生的重大新闻
  • 政府网站建设预算seo哪家强
  • 濮阳网络直播什么是seo推广
  • 建网站服务器用什么如何在各大网站发布信息
  • 大型网站建站长沙市最新疫情
  • 罗玉凤做网站做了5天游戏推广被抓了