是什么使jQuery.print无法与Leaflet一起使用? [英] What is keeping jQuery.print from working with Leaflet?

查看:138
本文介绍了是什么使jQuery.print无法与Leaflet一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在测试使用jQuery.print的git回购(此处的演示)时,我收到以下错误:

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

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

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

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

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

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

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

推荐答案

原因是同一个起源政策-除非使用 CORS 请求图像,否则它们会在浏览器. 传单-图像重新请求图像以解决此问题.

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.

这篇关于是什么使jQuery.print无法与Leaflet一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆