问题
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