[英]oncopy event not fired in leaflet
I want to catch the copy event that is fired when the user presses Ctrl+C . 我想捕获用户按下Ctrl + C时触发的复制事件。 For some reasons it is not fired when the user interacts with the map.
由于某些原因,当用户与地图交互时不会触发它。 I've tried to automatically set the focus on the #map div, but it didn't help.
我试图自动将焦点设置在#map div上,但它没有帮助。
Here is a working example of a div that gets the oncopy event http://jsfiddle.net/669a62dn/ document.getElementById('map').addEventListener('copy', function (e) { console.log(e); });
这是一个div的工作示例,它获取oncopy事件http://jsfiddle.net/669a62dn/
document.getElementById('map').addEventListener('copy', function (e) { console.log(e); });
And here's a map that doesn't work: http://jsfiddle.net/b4ueu63f/ 这是一张不起作用的地图: http : //jsfiddle.net/b4ueu63f/
Any help is appreciated. 任何帮助表示赞赏。 Thanks!
谢谢!
You say "[The copy event] is not fired when the user interacts with the map." 你说当用户与地图交互时,不会触发“[复制事件]。” However, it works for me.
但是,它对我有用。 If I select the
Leaflet | © OpenStreetMap contributors
如果我选择
Leaflet | © OpenStreetMap contributors
Leaflet | © OpenStreetMap contributors
text at the base of the map and press Ctrl-C, an event is fired. Leaflet | © OpenStreetMap contributors
在地图底部显示文本并按Ctrl-C,触发一个事件。
Possibly when you were testing, you did not select anything to copy, and consequently, when you tried to copy, nothing happened because nothing was selected. 可能在您进行测试时,您没有选择要复制的任何内容,因此,当您尝试复制时,没有任何事情发生,因为没有选择任何内容。
I think the problem here may be that the map itself cannot be selected and therefore cannot be copied, only the text in the map div can. 我认为这里的问题可能是地图本身无法选择,因此无法复制,只有地图div中的文本可以。 This means the copy event handler may not be behaving as you expect.
这意味着复制事件处理程序可能没有按预期运行。
It seems you can't trigger the copy
event on the map iteslf. 看来你无法在地图iteslf上触发
copy
事件。
But you could trick the map like this : 但你可以像这样欺骗地图:
copy
event on this element. copy
事件。 Example : http://jsfiddle.net/j381ybe1/ 示例: http : //jsfiddle.net/j381ybe1/
The only change is the copy
event is triggered on the input
element and when you click on the map you insert some text on the input. 唯一的变化是在
input
元素上触发copy
事件,当您单击地图时,在input
上插入一些文本。
I found a solution here but had some trouble translating the coffee script in js mainly because I'm new to this. 我在这里找到了一个解决方案,但在js中翻译咖啡脚本时遇到了一些麻烦,主要是因为我是新手。 How does Trello access the user's clipboard?
Trello如何访问用户的剪贴板?
var clipboardCont = L.DomUtil.get('clipboard-container');
L.DomUtil.setStyle(clipboardCont, 'display', 'inline');
var textArea = L.DomUtil.get('clipboard');
textArea.focus();
textArea.select();
It worked in the end. 它最终奏效了。 Thanks for the answers
谢谢你的回答
It works for input elements. 它适用于输入元素。
Look, I forked the jsBin 看,我分叉了jsBin
http://jsfiddle.net/tb0ek6q4/ http://jsfiddle.net/tb0ek6q4/
<input id='clipboard' value="HELLO WORLD!">
<div id="log"></div>
script 脚本
document.getElementById('clipboard').addEventListener('copy', function (e) {
document.getElementById('log').innerHTML += e;
});
But what do you mean with ' the client copies id="map" '? 但是你的意思是'客户端复制id =“map”'?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.