首页 > 移动平台 > 详细

APP中关于Android和IOS与网页交互

时间:2018-03-30 10:01:42      阅读:187      评论:0      收藏:0      [点我收藏+]

安卓交互:

    //安卓js代码start
    function bntcat(){
        if(isAndroid){
            musicPause()
        }
        var str = ‘{"tips":2018,"type":3}‘;
        JsCallback.jsMethod(str);
    }
    //安卓js代码end

IOS交互:

    //ios js代码start
    /****************************ios固定写法start**********************************/
    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 = ‘wvjbscheme://__BRIDGE_LOADED__‘;
        document.documentElement.appendChild(WVJBIframe);
        setTimeout(function () {
            document.documentElement.removeChild(WVJBIframe)
        }, 0)
    }
    /****************************ios固定写法end**********************************/
    setupWebViewJavascriptBridge(function (bridge) {
        $(".xxxxxx").click(function(){
            var id= $(this).data("id"),
            str = ‘{"tips":2018,"type":1,"gid":‘+id+‘}‘;           
            bridge.callHandler(‘nhjGoodsDetails‘, str, function (responseData) {})
        });
        bridge.registerHandler(‘miusicPlay‘, function (data, responseCallback) {
            $("#playAudio").addClass(‘on‘);
            document.getElementById("myaudio").play();
            responseCallback({‘userId‘: ‘123456‘, ‘blog‘: ‘miusicPlay‘})
        });
        bridge.registerHandler(‘miusicPause‘, function (data, responseCallback) {
            $("#playAudio").removeClass(‘on‘);
            document.getElementById("myaudio").pause();
        })
    });
    //ios js代码end

  

APP中关于Android和IOS与网页交互

原文:https://www.cnblogs.com/mracale/p/8674344.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!