【发布时间】:2012-09-17 06:03:56
【问题描述】:
当尝试从预先绘制图像的画布中读取图像数据时,Google Chrome 会引发跨源异常(抱怨画布被“污染”)。目录结构如下。
/html/base/path
|-- index.html contains the canvas element, references the script.js
|-- script.js loads imgs/images.jpg, paints and queries the canvas
`-- imgs/image.jpg
该错误仅在页面由 file:// 方案加载时发生。
我想知道这是否是 Chrome 错误。如果不是,适用哪些规则?有什么解决方法吗?
不幸的是,离线观看是终极用例,所以
- file://方案必不可少
- 无法控制目标系统的浏览器设置。
【问题讨论】:
-
关于那个的 MDN:developer.mozilla.org/en-US/docs/…
-
谢谢@m90。奇怪的是,MDN 上的规则明确允许上述过程:只有当源文件的父目录是目标文件的祖先目录时,一个文件才能读取另一个文件
-
也高度相关:stackoverflow.com/questions/3481977/is-there-a-way-to-bypass-javascript-jquerys-same-origin-policy-for-local-acce
-
@m90 没有 ajax,没有 getjson 没有外部 url。对我来说,这种关系似乎并不那么牢固,但谢谢!
标签: javascript html google-chrome cross-domain