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

安卓交互:

    //安卓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

  

posted @ 2018-03-30 09:08  zhuzhipeng  阅读(319)  评论(0编辑  收藏  举报