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

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

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

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

 $.print("map" /*, options*/); [Exception... "The operation is insecure." code: "18" nsresult: "0x80530012 (SecurityError)" location: ""] "Failed to print from iframe" undefined "The operation is insecure." jQuery.print.js:141 $.fn.print() jQuery.print.js:141  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: ""] 

jQuery.print演示本身在我的机器上运行良好。 为什么将它与Leaflet混合会产生安全性错误?

原因是同源策略 – 除非使用CORS请求图像,否则它们会在浏览器中触发此安全问题。 传单图像重新请求图像以解决此问题。