Safari iOS没有加载Javascript文件? [英] Safari iOS not loading Javascript file?

查看:2123
本文介绍了Safari iOS没有加载Javascript文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚升级了我的iOS,因为最近的 security bug ,我发现我的网站已经不能在我的手机上正常加载了!



我解决了问题下面是一个简单的例子...

index.html =

 < HTML> 
< head>
< title> Demo< / title>
< meta name =descriptioncontent =基本Javascipt函数的测试>
< script src =demo.js>< / script>
< / head>
< body class =body>
< div id =main>
< / div>
< / body>
< / html>

demo.js =

  var i = 0; 

函数update(){
'use strict';
document.getElementById(main)。innerHTML = i;
i = i + 1;
}
setInterval(update,1000);

在我的桌面上,这会产生迭代计数,但在使用手机上的Safari查看时(Mobile / 12G34 Safari / 601.1)JavaScript文件根本不会加载???? JavaScript文件甚至不会显示在我的WebInspector中的所有资源选项卡下,我通过USB进行共享。



建议?



谢谢,

Bill




<编辑:
这个问题没有得到回应,但我仍然在解决这个问题。我找到了更多的信息。



使用Safari WebInspector我发现javascript没有加载,因为...


禁止在 http://192.168.133.1/demo .html ',因为
文档的框架已被沙盒化,'allow-scripts'权限
未设置。


由于我在esp8266上为这个网页提供了一个土豆网络服务器,这个消息激发了我调整我的HTTP头。 HTTP标头看起来很好。



我无法弄清楚这个html页面是如何变得沙箱的,以及如何'allow-scripts',以便我可以在Safari中运行我的脚本Mobile。



任何帮助都将不胜感激。

解决方案

I在为我的Arduino项目实现Web服务器功能时遇到同样的问题。我的web服务器实现在桌面浏览器和iOS中的Chrome(9.3.5)上运行良好。我在iOS中遇到了Firefox(5.1(1))和Safari的问题。我的网页使用包括jQuery的脚本。脚本用于通过AJAX / JSON从Arduino传输数据。



问题出在我用作实现基础的示例中。在这些例子中,在OK的情况下,web服务器对浏览器的HTTP GET请求的回复不包含除请求的实际文档以外的任何内容。在这种情况下,Web浏览器认为Web服务器正在使用HTTP / 0.9。另外,缺少Content-Type。大多数浏览器可以猜测回复的内容类型,尽管它不包括在内。



在我的例子中,Safari报告了两个错误


  1. 阻止脚本在 http:// myip 中执行,因为文档的
    框架已经过沙盒处理,并且未设置'allow-scripts'权限。

  2. 沙盒 http://myip/image.jpg ',因为它使用HTTP / 0.9。

第一个错误导致浏览器拒绝加载我的JavaScript和jquery.js。当然之后,AJAX将无法正常工作。桌面上的Firefox也唠叨关于格式不正确的JSON回复,但仍然正常工作。

我只是简单地改变了实现,以便HTTP回复在实际数据之前总是包含HTTP版本,状态代码和Content-Type。例如,当浏览器发送请求 GET / HTTP / 1.1 时,服务器不仅仅发送默认网页,而且还包括

  HTTP / 1.1 200 OK 
Content-Type:text / html

之后,所有错误消失。看来Safari的新版本不喜欢接收HTTP / 0.9,并且会对沙盒的内容进行沙盒处理。


I have just upgraded my iOS because of the recent security bug, and I find that my website is no longer loading properly on my phone!

I've boiled the problem down to a simplified example...

index.html =

<html>
<head>
    <title>Demo</title>
    <meta name="description" content="Test of basic Javascipt function">
    <script src="demo.js"></script>
</head>
<body class="body">
    <div id="main">
    </div>
</body>
</html>

demo.js =

var i = 0;

function update() {
    'use strict';
    document.getElementById("main").innerHTML = i;
    i = i + 1;
}
setInterval(update, 1000);

On my desktop this produces an iterating count, but when viewed with Safari on my phone (Mobile/12G34 Safari/601.1) the javascript file simply does not load???? The Javascript file doesn't even show up under the "All Resources" tab in my WebInspector which I am tethering via USB.

Suggestions?

Thanks,

Bill


Edit: This question has gotten no response, but I'm still wrestling with this problem. I've found some more information.

Using the Safari WebInspector I've found that the javascript is not loading because...

Blocked script execution in 'http://192.168.133.1/demo.html' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.

Since I'm serving this page off a homespun webserver on an esp8266, this message has inspired me to tune up my HTTP headers. The HTTP headers appear to be fine.

I can't figure out how this html page is getting sandboxed in the first place, and how to 'allow-scripts' so that I can run my script in Safari Mobile.

Any help would be much appreciated.

解决方案

I had exactly same issue when implementing web server functionality for my Arduino project. My web server implementation worked fine with desktop browsers and with Chrome in iOS (9.3.5). I had problems both with Firefox (5.1 (1)) and Safari in iOS. My web pages use scripts including jQuery. Scripts are used for transferring data from Arduino with AJAX/JSON.

The problem was in the examples I used as a basis for my implementation. In those examples, web server's reply to browser's HTTP GET request in OK case doesn't contain anything else than the actual document requested. In that case web browser thinks that the web server is using HTTP/0.9. In addition, Content-Type is missing. Most of the browsers can "guess" what is the Content-Type of the reply although it is not included.

In my case, Safari reported two errors

  1. Blocked script execution in http://myip because the document's frame is sandboxed and the 'allow-scripts' permission is not set.
  2. Sandboxing http://myip/image.jpg' because it is using HTTP/0.9.

The first error causes browser to refuse loading my javascript and also jquery.js. Of course after that AJAX won't work. Firefox in desktop also nagged about not well-formed JSON replies but still worked fine.

I simply changed the implementation so that HTTP replies will always include HTTP version, status code and Content-Type before the actual data. For example, when browser sends request GET / HTTP/1.1, the server doesn't just send the default web page but includes

HTTP/1.1 200 OK
Content-Type: text/html

After that all errors disappeared. It seems new versions of Safari don't like to receive HTTP/0.9 and will sandbox what it gets back.

这篇关于Safari iOS没有加载Javascript文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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