Maison  >  Questions et réponses  >  le corps du texte

javascript - html5 使用 Content-Security-Policy 安全策略 导致ios10 与js 交互的代码不执行 ?

html5 使用 Content-Security-Policy 安全策略 导致ios10 与js 交互的代码不执行 自己的js代码正常

我的设置如下:

<meta http-equiv="Content-Security-Policy" content="default-src *;child-src *; frame-src *; style-src 'self' http://*.qq.com 'unsafe-inline' *; script-src 'self' 'unsafe-inline' 'unsafe-eval' http://*.qq.com wvjbscheme://__BRIDGE_LOADED__ *;">

ios10 的脚本一直注入失败 (ios 端交互方式使用的是 WebViewJavascriptBridge )
无法执行ios 方法

ios 与 js 交互代码使用如下方式:

 function setupWebViewJavascriptBridge(callback) {
        if (Platform == "ios") {
            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)
        }
    }
    

大神求指点,该怎么设置?

天蓬老师天蓬老师2720 Il y a quelques jours923

répondre à tous(2)je répondrai

  • 怪我咯

    怪我咯2017-04-11 10:14:05

    我自己的解决方案:由于ios10 的安全策略经过优化处理,如果有与ios 交互使用jsbridge库需要添加信任的frame-src,

    如:(这些src需要与源码中的路径匹配)

    frame-src 'self' wvjbscheme://* 根据具体项目中的交互库的源码中对应的路径

    具体代码如下:

    <meta http-equiv="Content-Security-Policy" content="default-src *; frame-src 'self' wvjbscheme://*; style-src 'self' http://*.xxx.com 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval' http://*.xxx.com;">

    répondre
    0
  • PHP中文网

    PHP中文网2017-04-11 10:14:05

    <meta http-equiv="Content-Security-Policy" content="default-src * data: cdvfile: gap:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"/>

    répondre
    0
  • Annulerrépondre