是什么让jQuery.印刷从工作与传单

What is keeping jQuery.print from working with Leaflet?

本文关键字:工作 jQuery 是什么      更新时间:2023-09-26

在测试使用jQuery的git repo时。打印(在这里演示),我得到以下错误:

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

我用jQuery在本地的传单实例上测试了这一点。通过将以下内容粘贴到控制台中打印,并且能够复制它:

$.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。打印演示本身在我的机器上工作良好。为什么将它与传单混合使用会产生安全错误?

原因是同源策略—除非使用CORS请求图像,否则它们会在浏览器中触发此安全问题。