What is keeping jQuery.print from working with Leaflet?

余生长醉 提交于 2020-03-05 07:07:12

问题


When testing a git repo that makes use of jQuery.print (demo here), I got the following error:

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

I tested this on a local Leaflet instance with jQuery.print by pasting the following into the console, and was able to replicate it:

$.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

This also happened even if I disabled the option to build an iframe for printing:

$("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>"]

The jQuery.print demo itself works fine on my machine. Why does mixing it with Leaflet create security errors?


回答1:


The reason is the Same Origin Policy - unless images are requested with CORS, they trigger this security issue in browsers. leaflet-image re-requests images to work around this.



来源:https://stackoverflow.com/questions/25172591/what-is-keeping-jquery-print-from-working-with-leaflet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!