H5 调用 Android 和 iOS 方法

function share(){
    var u = navigator.userAgent;
    if(u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {
            //安卓手机
            android.andshare(title,content,url)
    }else if(u.indexOf('iPhone') > -1) {
            setupWebViewJavascriptBridge(function(bridge) {
               bridge.callHandler('iosshare', {'title':title,'content':content,'url':url}, function responseCallback(responseData) {
                   console.log("JS received response:", responseData);
                     })
             })
    }
}

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)
    }
H5
本作品采用《CC 协议》,转载必须注明作者和本文链接
持续做一件事,必定有所成就
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 2

标题什么意思

5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!