I recently read statements saying:
as you know can not copy or paste anything on top of a SVG ... e.clipboardData.getData('Text'), so this method managed to paste something in SVG
About this quote I want to highlight some problems of understanding:
ClipboardData.getData()
has existed since Internet Explorer 5.5, browser released in 2000
- SVG is only supported in Internet Explorer 9, browser released in 2011
- IE5.5 and IE9 are 11 years apart and the method
ClipboardData.getData()
existed before SVG support.
So there’s no reason why getData
be an advantage for the SVG, the real "advantage" is to apply what is in the Clipboard user for an action customized as required by the project/application.
The use within the event paste
is a mere example only, but could be used otherwise and in other events (such as copy
, I quoted an example near the end of the answer).
It’s not like you can’t glue anything to SVG, just can’t stick anywhere that ISN’T:
INPUT
TEXTAREA
- And who doesn’t have the attribute
contentEditable
(or document with designmode
, popularly called "richtext")
I mean, not even glue on one DIV you’ll get.
With ClipboardData.getData()
it is possible to get the user’s Clipboard at an opportune time so that you can customize the action, as well as edit a DIV or SVG at runtime so that it presents the value that was in the Clipboard.
An example, assuming you have a richtext system (contentEditable
or designMode
), which allows the web to edit the HTML as if it were the microsoftword or similar program, you could prevent the user to insert improper things into the HTML, cleaning the contents of the obtained Clipboard, leaving only the tags allowed.
Another example would be in the event copy
to check if the current value of the Clipboard already meets a need and prevents copying another, then to check the current value would have to use the getData
also, this of course depending on the need of those developing the application.
The use and advantage of getData
goes from the need of the environment and what you actually need, a method or function does not need to be created with such a specific purpose, the basic purpose of the getData
is this, get the Clipboard, what you will do with it after this is of intent and need exclusively yours, so so many Apis (not only of Clipboard) allow "handlers" (handlers), so that the developer customizes the action according to a personal need.
An important detail is that although today’s method is functional in virtually all browsers, it was not something common except in IE, it was only changed over time, and as the implementation was based on IE for the others it is likely that this is the reason why it is flagged as experimental in some documentations.
When you say "this code makes me paste a number copied from elsewhere" you already explain what that code does... what doubt you have left?
– Sergio
I thought that there was a higher definition or that it was used in other ways I looked in various forúns and I did not find much about it not...
– user136702