Skip to main content
Participant
March 18, 2011
Question

Paste from clipboard not working

  • March 18, 2011
  • 1 reply
  • 393 views

This HTML in AIR does not work correctly ... an

yone know why?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TEST</title>

<script language="JavaScript" type="text/javascript">
function fixFMT(event) {
  var cs = event.clipboardData.getData("text/plain");
  if(!cs) return;
  // processing for cs not shown
  // now want to insert cs into the textarea in place of the selection.
  var sel = window.getSelection();
  var rng = sel.getRangeAt(0);
  var insertion = document.createElement("b");
  insertion.innerHTML = cs;
  rng.insertNode(insertion);
  sel.removeAllRanges();
  event.preventDefault();
}
</script>
</head>

<body>
<form>
<table>
        <tr><th>Paste text into the text area - then click outside and see it disappear.</th></tr>
        <tr><td>
             <textarea id="t1" name="t1" rows="4" cols="40" onpaste="fixFMT(event);" ></textarea>
            </td>
        </tr>
</table>
</form>
</body>
</html>

This topic has been closed for replies.

1 reply

GE_JOHNAuthor
Participant
March 20, 2011

Resloved:

data type was wrong ...

the line: var cs = event.clipboardData.getData("text/plain");
should be: var cs = event.clipboardData.getData("text/html");

With this change, all works.