4

How to copy CSS RTL directed format to the clipboard?

I get this text in the clipboard: moc.liam@liam, but I want this: mail@mail.com

Using this code to copy:

<script>
function CopyKey(elementId) {
var aux = document.createElement("input");
aux.setAttribute("value", document.getElementById(elementId).innerHTML);
document.body.appendChild(aux);
aux.select();
document.execCommand("copy");
document.body.removeChild(aux);
}
</script>

<p id="key" class="rev" onclick="CopyKey('key')">moc.liam@liam</p>

.rev {
unicode-bidi: bidi-override;
direction: rtl;
}

EDIT (WORKING CODE)

function Reverse(s){
  return s.split("").reverse().join("");
}

function CopyKey(elementId) {
  var aux = document.createElement("input");
  aux.setAttribute("value",    Reverse(document.getElementById(elementId).innerHTML));
  document.body.appendChild(aux);
  aux.select();
  document.execCommand("copy");
  document.body.removeChild(aux);
}
X11
  • 332
  • 4
  • 19

1 Answers1

6

JavaScript ignores the css attributes. You need to write some code to reverse the string.

function reverse(s){
    return s.split("").reverse().join("");
}

Please refer to this answer for more information about reversing strings in JavaScript: https://stackoverflow.com/a/16776621/8649828

kwyntes
  • 1,045
  • 10
  • 27