需求:在webview中点击http连接,调用android默认的浏览器。这样在关闭url连接时,依然可以回到webview页面继续浏览
解决方案:
1、定义一个webview mwebview
2、在webView中加载url
3、设置webview参数:
mwebview.getSettings().setJavaScriptEnabled(true);
mwebview.addJavascriptInterface(new Object(){
public void openBrowser(String url){
Uri uri = Uri.parse(url);
Intent iten = new Intent(Intent.ACTION_VIEW,uri);
startActivity(iten);
}
}, "openBrowser");其中:内部类中的方法openBrowser就是用来加载在webview中传来的url
4、在html 设置当点击http时,触发openBrowser函数。
<u><a onClick="window.openBrowser.openBrowser('http://www.ct10000.com/main/wifibuy/')" style="color:#0000FF">http://www.ct10000.com/main/wifibuy/</a></u>
其中:调用函数的方法:window.openBrowser.openBrowser(),参数要用单引号‘’
webView 支持javascript
最新推荐文章于 2025-11-16 12:21:32 发布
本文介绍如何在Android WebView中实现点击HTTP链接时使用默认浏览器打开,并确保用户能返回WebView页面。通过定义WebView、设置参数及JavaScript接口,实现在外部浏览器中打开链接的功能。
260

被折叠的 条评论
为什么被折叠?



