Apache Cordova App允许外部脚本 [英] Apache Cordova App allow external scripts

查看:86
本文介绍了Apache Cordova App允许外部脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在通过visual studio构建一个apache cordova移动应用程序,并遇到了试图通过我的应用中的外部脚本运行小部件的问题。这些脚本在浏览器模拟器中运行良好,但是一旦我尝试在苹果设备上运行它们,脚本就不会加载。我已经研究了这个问题,并发现它通常与内容安全策略有关,我在下面附上这些内容以帮助解决问题。

 < meta http-equiv =Content-Security-Policycontent =default-src *; style-src' self'';'*'unsafe-inline'; script-src'self'*'unsafe-inline''unsafe-eval'; img-src'self'*'unsafe-inline''unsafe-eval'/ > 

还有什么可能是这些小部件为什么不在我的应用程序中加载的问题?这些是我尝试加载到我的应用程序中的脚本,供您参考。

 < script type =text / javascriptsrc =https://rf.revolvermaps.com/0/0/8.js?i=5tfq2n8w5rc&amp;m;0c&amp;c=cbb677&amp;cr1=ffffff&amp;f= calibri& 1 = 0& amp; amp; cw = ffffff& amp; cb = 450084async =async>< / script> 

< script type =text / javascriptsrc =https://rf.revolvermaps.com/0/0/0.js?i=5gbey55pbu3&amp;d=2&amp ; p = 1&安培;和b = 1&放大器;放大器; W = 293&放大器;放大器; G = 1&放大器;放大器; F =宋体&放大器;放大器; FS = 12&放大器;放大器; R = 0&放大器;放大器; C0 = 362b05&放大器;放大器; C1 = 450084& c2 = 000000& ic0 = 0& amp; ic1 = 0async =async>< / script>


解决方案

脚本和链接标记中的src和href应该有一个方案(http或https),否则,当Cordova发现//时,它将使用它的默认方案file:。您的脚本和链接标签,然后它应该可以工作。



例如:

 < script type =text / javascriptsrc =http://rf.revolvermaps.com/0/0/8.js?i=5tfq2n8w5rc&amp;m=0c&amp;c=cbb677&amp ; cr1 = ffffff& amp; f = calibri& amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; cw = ffffff& amp; cb = 450084async =async>< / script> 


I am currently building an apache cordova mobile app through visual studio and have run into the problem of trying to run widgets through external scripts in my app. These scripts run fine in the browser simulator but once I try to run them on an apple device, the scripts do not load. I have researched into this problem and found that it usually has something to do with the content security policy, which I have attached below to help figure out the problem.

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

What else could possibly be the problem as to why these widgets are not loading in my app? These are the scripts I am attempting to load inside of my app for your reference as well.

<script type="text/javascript" src="https://rf.revolvermaps.com/0/0/8.js?i=5tfq2n8w5rc&amp;m=0c&amp;c=cbb677&amp;cr1=ffffff&amp;f=calibri&amp;l=0&amp;cw=ffffff&amp;cb=450084" async="async"></script>

<script type="text/javascript" src="https://rf.revolvermaps.com/0/0/0.js?i=5gbey55pbu3&amp;d=2&amp;p=1&amp;b=1&amp;w=293&amp;g=1&amp;f=calibri&amp;fs=12&amp;r=0&amp;c0=362b05&amp;c1=450084&amp;c2=000000&amp;ic0=0&amp;ic1=0" async="async"></script>

解决方案

Your src and href from the script and link tags should have an scheme (http or https), otherwise, when Cordova finds //, it will use it's default scheme, file:.

Add http: or https: to all your script and link tags and then it should work.

Example:

<script type="text/javascript" src="http://rf.revolvermaps.com/0/0/8.js?i=5tfq2n8w5rc&amp;m=0c&amp;c=cbb677&amp;cr1=ffffff&amp;f=calibri&amp;l=0&amp;cw=ffffff&amp;cb=450084" async="async"></script>

这篇关于Apache Cordova App允许外部脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆