码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2018-03-30 10:15:23      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:timeout   fun   play   get   settime   child   ios   tar   call   

安卓交互:

    //安卓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与网页交互

标签:timeout   fun   play   get   settime   child   ios   tar   call   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!