• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

JavaScript Code does not work in all browsers

Hi Experts,

I have the code below working in IE, but not in Fireiox and Chrome. Can anyone tell me why and how to fix it?

Thank you

<html>

<body>

<input type="text" id="txt" value="abcdef...xyz">

<input type="BUTTON" onClick="ClipBoard()" value="Copy to Clipboard" >

<TEXTAREA ID="holdtext" STYLE="display:none;">
</TEXTAREA>

</body>


<SCRIPT LANGUAGE="JavaScript">

    function ClipBoard() {
        holdtext.innerText = txt.value;
        Copied = holdtext.createTextRange();
        Copied.execCommand("Copy");
    }

</SCRIPT>



</html> 

Open in new window

0
APD Toronto
Asked:
APD Toronto
  • 5
  • 4
1 Solution
 
Dave BaldwinFixer of ProblemsCommented:
It looks like your code is not correct or complete enough.  See here for Mozilla / Firefox info: https://developer.mozilla.org/en-US/docs/Rich-Text_Editing_in_Mozilla#Executing_Commands
0
 
APD TorontoAuthor Commented:
so, how can i make my code work in both, IE and FF?
0
 
Dave BaldwinFixer of ProblemsCommented:
Try the sample code in the Mozilla link above.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
APD TorontoAuthor Commented:
i don't understand
0
 
Dave BaldwinFixer of ProblemsCommented:
This page https://developer.mozilla.org/en-US/docs/Rich-Text_Editing_in_Mozilla#Executing_Commands includes a complete Rich-Text editor at the bottom of the page that includes the command you are trying to use.  Make up a test page and try their code.
0
 
APD TorontoAuthor Commented:
I'm not doing any rich-text editting, i just need to copy to clipboard, as per my code above
0
 
Dave BaldwinFixer of ProblemsCommented:
Did you look at that page and how they are using the commands to copy to the clipboard?
0
 
APD TorontoAuthor Commented:
I can't see it.  Can you paste the code here please
0
 
APD TorontoAuthor Commented:
could not figure out
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now