Oncopy event not released in brochure

I want to catch up event that is triggered when the user presses the Ctrl + the C . For some reason, it doesn't start when the user interacts with the map. I tried to automatically set focus to the #map div, but it didn't help.

Here is a working example of a div that receives an oncopy event http://jsfiddle.net/669a62dn/ document.getElementById('map').addEventListener('copy', function (e) { console.log(e); });

And here is a map that doesn't work: http://jsfiddle.net/b4ueu63f/

Any help is appreciated. Thank!

+3


source to share


4 answers


I found a solution here, but had some problems translating the coffee script to js mainly because I am new to this. How does Trello access the user's clipboard?

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 answers

0


source


You say, "[Copy event] doesn't fire when the user interacts with the card." However, this works for me. If I select text Leaflet | Β© OpenStreetMap contributors

in the map base and press Ctrl-C, an event occurs.

It is possible that when you tested, you did not select anything to copy, and therefore, when you tried to copy, nothing happened because nothing was selected.



I think the problem here might be that the map itself cannot be selected and therefore cannot be copied, only the text in the map div can. This means that the copy event handler may not behave as you expect.

+1


source


You can't seem to trigger an event copy

on the iteslf map.

But you can cheat the card like this:

  • Add an input that will contain the required data for copying.
  • When clicking on the map: add data to the tab and focus on it.
  • Then you can use an event copy

    on that element.

Example: http://jsfiddle.net/j381ybe1/

The only change is this event is copy

triggered on the element input

and when you click on the card you are pasting some text to the input.

0


source


It works for input elements.
See I forked jsBin

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 by "client copies id =" map "??

-1


source







All Articles