This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.

Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!

Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

IE vs Firefox Copy to clipBoard javascript issue  RSS feed

pulijala hari
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am trying to implement the copy to clipboard functionality using javascript.
Here is my function :
function copyText(field)
var content = eval("document."+field)
range = content.createTextRange()
window.status="Contents copied to clipboard"
var gClipboardHelper = Components.classes[";1"];
const setClbHelper=gClipboardHelper.getService(Components.interfaces.nsIClipboardHelper);

Where the parameter field is myForm.txtBox and i am having my text in this box which has to be copied.
When i work on the Firefox, this works fine but it does not work on IE.
But when i invoke only IE related part, it works fine on IE.
The issue comes up when i use if and else to check for the browser and IE does not copy when i have the Firefox related code in the else.
Could any one help me point the error.

Bear Bibeault
Author and ninkuma
Posts: 65824
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.

Eric Pascarello
Posts: 15385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has to be enabled with browser settings. Most people are NOT going to enable it.

It might be better to look at a flash solution sort of like this:

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!