2017-08-14 47 views
0

好的,所以我已經看到所有的線程,但似乎無法得到它的工作。在科爾多瓦wkwebview注入內聯腳本IOS

<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; media-src *; img-src *"> 

如果我直接添加:

<script type="text/javascript"> 
     alert('Hello world'); 
</script> 

這個工程。

..但..如果我從localStorage注入它崩潰的應用程序。我可以完全正確地注入html和css。

我已經安裝了這些國家防範機制:

<plugin name="cordova-plugin-wkwebview-engine" spec="git+https://github.com/apache/cordova-plugin-wkwebview-engine.git#1.0.0" /> 
<plugin name="cordova-plugin-wkwebview-file-xhr" spec="^1.0.0" /> 
+0

向我們展示瞭如何從localStoage – Eric

回答

0

我用這個小功能加載它。與UIWebView的

Nate.createScript = function(input){ 
    var head = document.getElementsByTagName('head')[0] 
    var el = document.createElement('script') 
    el.setAttribute('type', 'text/javascript') 
    el.innerText = input 
    head.appendChild(el) 
} 

作品和localStorage的看起來像:

localStorage.js = "alert('hello world')"; 
Nate.createScript(localStorage.js) 
+0

其實,這工作加載整個JS這是當-.- 問題顯然在於注入的WebPack生成的代碼。 它在xcode中引發此錯誤: WebPageProxy.DecidePolicyForNavigationAction 它在safari控制檯中抱怨,在崩潰之前找不到一些字體 – AndersD