Hi Harish,
I am sorry I was not aware of I had another version of code doing copy/paste
for FF. FF is complicate to support copy/paste due to user privilage
protection. In addition to your code below, you still need to follow FF's
requirement to open privilage of copy/paste:
http://www.mozilla.org/editor/midasdemo/securityprefs.html
If you only want to make your copy/paste working on TextBox, there is an
easier way. You can use below method to get any user selection:
public static native String copyFrom() /*-{
var sel = $wnd.window.getSelection();
return sel.toString();
}-*/;
And then insert the text string you got into your TextBox.
Kevin
On 3/25/09, Harish Nair <[email protected]> wrote:
>
> I got this code from web its still not working is there any change i should
> make to run and copy text to clipboard.
>
> public static native void copyFrom(String mytext) /*-{
> if (window.clipboardData)
> {
> // IE
> $wnd.window.clipboardData.setData('text', mytext);
> // Netscape
> }
> else if (window.netscape)
> {
>
> netscape.security.PrivilegeManager.enablePrivilege
> ('UniversalXPConnect');
> var clip =
> components.classes['@
> mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard<http://mozilla.org/widget/clipboard;1%27%5D.createInstance%28Components.interfaces.nsIClipboard>);
> if (!clip) return;
>
> //
> var trans =
> Components.classes['@
> mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransfera<http://mozilla.org/widget/transferable;1%27%5D.createInstance%28Components.interfaces.nsITransfera>ble);
> if (!trans) return;
>
> //
> trans.addDataFlavor('text/unicode');
>
> //
> var str = new Object();
> var len = new Object();
> var str =
>
> Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsS
> tring);
>
> var copytext=mytext;
> str.data=copytext;
> trans.setTransferData("text/unicode",str,copytext.length*2);
> var clipid=Components.interfaces.nsIClipboard;
> if (!clip) return false;
> clip.setData(trans,null,clipid.kGlobalClipboard);
> }
> alert("Following info was copied to your clipboard:\n\n" + mytext);
>
> }-*/;
>
>
> -harry
>
> 2009/3/24 Harish Nair <[email protected]>
>
>> Hi Kevin,
>>
>> This is not working in FF where as its working very well in IE. Please
>> advice me how to do it on FF as the site is going to run on that.
>>
>> -
>> Harry
>>
>>
>> 2009/3/24 Kevin Tarn <[email protected]>
>>
>>> It was tested in IE and Firefox. I am not sure whether it works on Chrome
>>> or Webkit.
>>>
>>> Kevin
>>>
>>>
>>> On 3/24/09, Dmitry Sterinzat <[email protected]> wrote:
>>>>
>>>>
>>>> Does it work only for IE or it's crossbrowser code?
>>>>
>>>> 2009/3/24 Kevin Tarn <[email protected]>:
>>>>
>>>> > You can try below JSNI methods:
>>>> > public static native void
>>>> copyFrom(com.google.gwt.user.client.Element
>>>> > element) /*-{
>>>> > $wnd.window.clipboardData.setData('text', element);
>>>> > }-*/;
>>>> >
>>>> > public static native void
>>>> pasteTo(com.google.gwt.user.client.Element
>>>> > element) /*-{
>>>> > $wnd.window.clipboardData.getData(element);
>>>> > }-*/;
>>>> >
>>>> > Kevin
>>>> >
>>>> > On 3/24/09, Harry <[email protected]> wrote:
>>>> >>
>>>> >> Hi,
>>>> >>
>>>> >> My project is that user is enabled to copy the content of a text box
>>>> >> and paste it on another form using 'Copy' button. Please advice how
>>>> to
>>>> >> do it as GWT is not support copying to system clipboard.
>>>> >>
>>>> >> Please help its important.
>>>> >>
>>>> >> Thanks
>>>> >>
>>>> >> Harry
>>>> >>
>>>> >
>>>> >
>>>> > >
>>>> >
>>>>
>>>>
>>>>
>>>>
>>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---