This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes IE vs Firefox Copy to clipBoard javascript issue Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "IE vs Firefox Copy to clipBoard javascript issue" Watch "IE vs Firefox Copy to clipBoard javascript issue" New topic
Author

IE vs Firefox Copy to clipBoard javascript issue

pulijala hari
Ranch Hand

Joined: May 14, 2005
Posts: 70
Hi,

I am trying to implement the copy to clipboard functionality using javascript.
Here is my function :
function copyText(field)
{
if(document.all){
var content = eval("document."+field)
content.focus()
content.select()
range = content.createTextRange()
range.execCommand("Copy")
window.status="Contents copied to clipboard"
setTimeout("window.status=''",1800)
}else{
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"];
const setClbHelper=gClipboardHelper.getService(Components.interfaces.nsIClipboardHelper);
setClbHelper.copyString("<%=urlBuffer%>");
}
}

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.

Thanks,
hari
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56183
    
  13

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.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15357
    
    6
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: http://ajaxian.com/archives/seeding-the-clipboard-in-flash10-with-zero-clipboard

Eric
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: IE vs Firefox Copy to clipBoard javascript issue
 
Similar Threads
Happy New Year! Welcome to our new forums!
Problem with mozilla firefox browser while creating dynamic dropdown list
blur() equivalent in firefox
How to copy a image to clipboard in FIREFOX browser using javascript?
Can We Invoke Keyboard Events On Button Press ?