跨终端开发

var u = navigator.userAgent,
app = navigator.appVersion;
var isAndroid = u.indexOf(‘Android’) > -1 || u.indexOf(‘Linux’) > -1; //g
var isIOS = !!u.match(/(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
if (isAndroid) {
window.localStorage.setItem(‘type’, ‘Android’);
}
if (isIOS) {
window.localStorage.setItem(‘type’, ‘iOS’);
}

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)
}

你可能感兴趣的:(web,web跨终端开发)