5

我正在使用一个脚本来检测 Javascript 错误并将它们报告给我的后端。但是,我收到了神秘的“脚本错误”消息,这对调试没有太大帮助。

根据神秘的“脚本错误”。在 Chrome 和 Firefox 中以 Javascript 报告的原因是因为引发错误的脚本来自与我的网站不同的来源。

由于我使用的是 CDN,因此我的所有脚本都有效地从另一个域提供。有没有办法在仍然使用 CDN 的同时获得更多有用的错误消息?

此外,一切都通过 SSL 提供,所以我想保留这种能力。

4

2 回答 2

1

我有一个类似的问题:我的脚本由一个子域提供服务并且属于同一来源限制。但是,我通过以下方式解决了这个问题:

1)像这样添加每个脚本标签:

<script type="text/javascript" src="http://subdomain.mydomain.tld" crossorigin="*.mydomain.tld" />

2)通过在每个虚拟主机中添加以下内容来修改 apache httpd.conf(您必须启用 mod_headers):

<IfModule mod_headers.c>
Header add Access-Control-Allow-Origin "*.mydomain.tld"
</IfModule>

在我的一台服务器上,除了替换之外,我无法使其正常工作

*.mydomain.tld

经过

*

请注意可能允许 * 钓鱼扩展信息的缺陷。有关 CORS、同源、img 和字体、cdn 的文档可用,但有关脚本标签跨域详细信息的可用文档非常少。

希望这可以帮助 ...

于 2012-09-18T12:55:36.350 回答
0

Try using jsonp for the dataType attribute in jQuery.ajax. The remote server will also need to support jsonp. It will get around the browser security preventing XSS.

Alternatively, you could use an IFrame and use jQuery within each window, but use HTML5 postMessage to communicate back and forth between the windows on two different domains.

Or, if you control both servers you can set the headers for same origin.

Jsonp has been my weapon of choice for this kind of problem. The others are just a legitimate.

于 2012-08-02T17:35:48.783 回答