d3地图仅适用于Firefox

时间:2016-08-02 17:13:36

标签: google-chrome firefox d3.js

所以,我在d3中有一张地图,它只适用于Firefox。它在chrome中不起作用。当我从pre-pros运行地图时,它可以工作 - 我不确定prepros是如何工作的,但它似乎在我的本地机器上部署了一个虚假服务器。所以使用Prepros,无论浏览器如何,一切都正常。如果没有在prepros上运行我的网站,这里有一些错误 - 我应该怎么做以确保跨浏览器兼容性?感谢。

//Some of the errors
file:///C:/Users/SXM274/My_Websites/Residents_Website/lib/d3.min.js Failed to load resource: net::ERR_FILE_NOT_FOUND
main2.js:11 initialized
main2.js:37 setting map
d3.v3.js:444 XMLHttpRequest cannot load file:///C:/Users/SXM274/My_Websites/Residents_Website/data/countries.topojson. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.xhr.send @ d3.v3.js:444
main2.js:87 callback funtion initialized
main2.js:90 Uncaught TypeError: Cannot read property 'objects' of undefined

1 个答案:

答案 0 :(得分:0)

出于安全原因,您无法使用XMLHttpRequest加载本地文件系统资源。您需要运行Web服务器,以便可以将Access-Control-Allow-Origin标头作为响应发送。

您可以通过将--allow-file-access-from-files标记传递给Chrome来解决此问题。

视窗:

chrome.exe --allow-file-access-from-files

的Mac:

open /Applications/Google\ Chrome.app/ --args --allow-file-access-from-files