當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JS和安卓 IOS的交互 例子式记录
生活随笔
收集整理的這篇文章主要介紹了
JS和安卓 IOS的交互 例子式记录
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
(function () {
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android終端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
if(isAndroid){
(function(){
function android_inter(){
let t_url = "xxxxxx";
document.getElementById("事件監聽的DOM節點").onclick = function () {
android.onNavigateByScheme(t_url);
}
}
android_inter();
})();
}else if(isiOS){
/**
* UIWebView與JS之間的橋接
*/
function setupWebViewJavascriptBridge(callback) {
if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
window.WVJBCallbacks = [callback];
var WVJBIframe = document.createElement('iframe');
WVJBIframe.style.display = 'none';
WVJBIframe.src = 'https://__bridge_loaded__';
document.documentElement.appendChild(WVJBIframe);
setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
}
let t_url = "xxxxxx";
document.getElementById("事件監聽的DOM節點").onclick = function () {
setupWebViewJavascriptBridge(function(bridge) {
bridge.callHandler("客戶端定義好的函數名",t_url, function (responseData) {
});
});
}
}
})();
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android終端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
if(isAndroid){
(function(){
function android_inter(){
let t_url = "xxxxxx";
document.getElementById("事件監聽的DOM節點").onclick = function () {
android.onNavigateByScheme(t_url);
}
}
android_inter();
})();
}else if(isiOS){
/**
* UIWebView與JS之間的橋接
*/
function setupWebViewJavascriptBridge(callback) {
if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
window.WVJBCallbacks = [callback];
var WVJBIframe = document.createElement('iframe');
WVJBIframe.style.display = 'none';
WVJBIframe.src = 'https://__bridge_loaded__';
document.documentElement.appendChild(WVJBIframe);
setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
}
let t_url = "xxxxxx";
document.getElementById("事件監聽的DOM節點").onclick = function () {
setupWebViewJavascriptBridge(function(bridge) {
bridge.callHandler("客戶端定義好的函數名",t_url, function (responseData) {
});
});
}
}
})();
轉載于:https://www.cnblogs.com/Neilisme/p/9560902.html
總結
以上是生活随笔為你收集整理的JS和安卓 IOS的交互 例子式记录的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 京东白条可以提现吗?取现看这两种方式
- 下一篇: git 使用