Will an onCopy event help me restore a bullet hole in my leg?

In the huge number table, I made the user experience richer by replacing all the semi-visible minus signs with – . It looks great, a big improvement. I was so busy admiring my mind that I forgot to notice the blood on the floor.

Because, find out when a guy is going to choose, copy, and then paste (elsewhere) such transformed minus signs, guess what? they are no longer negative signs.

Can I use the onCopy event reliably, directly and in a cross browser (including Mac browsers) to change these – negative signs in what was (or should be) copied?

If so, do you have any hints of this?

EDIT: I use my own JavaScript without using any framework.

Thanks!

+6
source share
2 answers

I do not believe that JavaScript can manipulate what is inside the clipboard because it is an OS feature. What you could do, I believe, is to manipulate the text after the user inserts it into the field of your choice. Here is an example with jQuery:

 $('#my_text_field').bind('paste',function() { $(this).val($(this).val().replace('–','-')); } 
+1
source

Symbol – will copy / paste correctly if it is pasted programmatically using javascript (and if you enter the actual character in place of the HTML object).

Perhaps you could replace every – which you have with something like:

 <span class="fancyDash"></span> 

And then at boot you can run something like:

 var longDash = '\u2013'; jQuery.each($(".fancyDash"), function() { this.innerHTML = longDash; }); 

Here is a working example: http://jsfiddle.net/m9fhS/

Edit:

Or, if you do not use jQuery, you can first fix document.getElementsByClassName so that it works correctly for everyone who uses IE, and then do:

 var longDash = '\u2013'; var spans = document.getElementsByClassName("fancyDash"); for (var index = 0; index < spans.length; index++) { spans[index].innerHTML = longDash; } 

As shown here: http://jsfiddle.net/m9fhS/1/

+1
source

Source: https://habr.com/ru/post/892279/


All Articles