Is it possible to make it so that when a user copies/pastes something onto their clipboard, it's CSS styles remain?
Asked
Active
Viewed 294 times
1
-
Copy and paste what? Text? Graphics? Something else? – Josiah Nov 05 '14 at 02:46
-
i dont think you can control the endusers clipboard. only the text gets copied onto the clipboard when a user selects a certain section of the page – Sai Nov 05 '14 at 02:47
-
No that is impossible. – TheProvost Nov 05 '14 at 02:50
-
@Josiah I mean `text-shadow`, `font-weight`, `color`, etc. – Kareem Kamel Nov 05 '14 at 02:58
2 Answers
1
If you are talking about HTML objects, then you can use this script mentioned here.
This script copies all the styles of a HTML Tag and stores them so that you can use them later on.
So in your case, when you somehow detect the copy event, you can store the style properties of the original object, and when the user pastes, you can apply the stored styles.
The original usege of the script :
var style = $("#original").getStyleObject(); // copy all computed CSS properties
$("#original").clone() // clone the object
.parent() // select it's parent
.appendTo() // append the cloned object to the parent, after the original
// (though this could really be anywhere and ought to be somewhere
// else to show that the styles aren't just inherited again
.css(style); // apply cloned styles
But maybe the easier way would be to add a class like .copied-tag when the user copies an object, then when the user pastes, you can find the .copied-tag class and apply any of the styles you want to copy.
An example:
When user copies:
$("#copied-object").addClass("copied-tag");
And when the user pastes:
originalObject = $(".copied-tag").removeClass("copied-tag");
newObject = $(originalObject)
.clone()
.css("text-shadow", $(originalObject).css("text-shadow"))
.css("color", $(originalObject).css("color"));
$("#container").append(newObject);
Community
- 1
- 1
Batuhan Tasdoven
- 798
- 7
- 19
0
Only if the styles are inline like this:
<p style="color:red">some text</p>
and they copy paste it into something that reads html.
Micro
- 10,303
- 14
- 82
- 120