HarmonyOS 鸿蒙Next中Web重定向问题
HarmonyOS 鸿蒙Next中Web重定向问题 使用的是API9,通过Web组件加载专题页链接:https://****.com/special/aaa.html
Web源代码内容大概如下:
<html>
<head>******</head>
<body>
<div>
<ul>
<li>
<a href="http://****.com/special/bbb.html"></a>
<div class="img">
<img src="http://img.****.com/aaa.jpg">
</div>
<div class="name">活动专题页</div>
<div class="adText">活动</div>
</li>
<li>
<a href="http://****.com/detail/商品Id.html"></a>
<div class="img">
<img src="http://img.****.com/bbb.jpg">
</div>
<div class="name">huawei手表</div>
<div class="adText">绝世好表</div>
</li>
</ul>
</div>
/body>
</html>
点击图片,触发href里的内容,怎么本地拦截href里的内容,本地判断href里的内容,跳转到指定的ets页面(类似安卓里的 shouldOverrideUrlLoading 回调函数)
更多关于HarmonyOS 鸿蒙Next中Web重定向问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html
这个不行,我还没加载完时,它就先拦截了跳了两次,直接把href里的页面跑了两次,我的效果是要点击图片,跳到本地原生的页面或者新的专题页,
这个和安卓shouldOverrideUrlLoading
一样的,
有要学HarmonyOS AI的同学吗,联系我:https://www.itying.com/goods-1206.html
有区别,自定义特殊的url(例如:tell://)在shouldOverrideUrlLoading可以拦截到,但是在onUrlLoadIntercept中就没有,
在HarmonyOS鸿蒙Next中,Web重定向问题通常涉及WebView组件的配置或网络请求的处理。确保在WebViewClient
中正确实现shouldOverrideUrlLoading
方法,以处理重定向逻辑。如果使用HttpURLConnection
或OkHttp
进行网络请求,需检查重定向策略,确保setInstanceFollowRedirects
或followRedirects
设置正确。此外,检查服务器端重定向配置,确保返回的HTTP状态码(如301、302)和Location
头信息正确。通过这些步骤,可以有效解决Web重定向问题。