Ras4U
Ras4U

Reputation: 492

TypeError: clipBoard.createTextRange is not a function

I am using

function CopyToClipBoard()
{
  clipBoard = document.getElementById('copyTemp'); 
  clipBoard.innerText = document.getElementById('copyFrom').value; 
  CopiedText = clipBoard.createTextRange(); 
  CopiedText.execCommand("Copy"); 
  clipBoard.innerText = ""; 
}

for copying a text from browser. On click I need to copy.

    <textarea id="copyTemp" style="position: absolute; visibility: hidden;"><?php echo $memMobile; ?></textarea>
<input type="hidden" id="copyFrom" value="<?php echo $memMobile; ?>">
<input type="button" value="Copy" onclick="CopyToClipBoard()">

then

TypeError: clipBoard.createTextRange is not a function

error is coming

Upvotes: 0

Views: 2842

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074495

As far as I can tell, createTextRange is an MS-only extension. It's not on the standard HTMLTextAreaElement or HTMLElement. There is a createRange on document.

For cross-browser range stuff, you might look at Tim Down's rangy.

Upvotes: 2

Related Questions