是什么让jQuery.print不能使用Leaflet?

时间:2014-08-07 00:50:56

标签: javascript jquery printing leaflet

在测试使用jQuery.print(demo here)的git repo时,我收到以下错误:

[Exception... "The operation is insecure."  code: "18" nsresult: "0x80530012 (SecurityError)"  location: "<unknown>"]

我在jQuery.print的本地Leaflet实例上通过将以下内容粘贴到控制台中进行了测试,并且能够复制它:

$.print("map" /*, options*/);

[Exception... "The operation is insecure."  code: "18" nsresult: "0x80530012 (SecurityError)"  location: "<unknown>"]
"Failed to print from iframe" undefined "The operation is insecure." jQuery.print.js:141
$.fn.print() jQuery.print.js:141
<anonymous function> debugger eval code:1

即使我禁用了构建iframe进行打印的选项,也会发生这种情况:

$("map").print({
    addGlobalStyles : true,
    stylesheet : null,
    rejectWindow : true,
    noPrintSelector : ".no-print",
    iframe : false,
    append : null,
    prepend : null
});

[Exception... "The operation is insecure."  code: "18" nsresult: "0x80530012 (SecurityError)"  location: "<unknown>"]

jQuery.print demo本身在我的机器上正常工作。为什么将它与Leaflet混合会产生安全性错误?

1 个答案:

答案 0 :(得分:0)

原因是the Same Origin Policy - 除非使用CORS请求图片,否则它们会在浏览器中触发此安全问题。 leaflet-image重新请求图片以解决此问题。