Thanks again,
In below method - how to get "event " ?  so as to use
event.clipboard.setData("text/plain", data), if I can get event handle then
I may achieve desired results.
public static native String setClipboardData(String data)/*-{

if($wnd.clipboardData && clipboardData.setData){
return $wnd.clipboardData.setData('Text',Data);
}
}
}-

On Thu, Oct 20, 2022 at 5:17 PM Vassilis Virvilis <[email protected]> wrote:

> I believe I did
>
> It's this snippet for copy
>
> event.clipboardData.setData("text/plain", data);
>
> On Thu, Oct 20, 2022 at 1:52 PM Pramod Patil <[email protected]>
> wrote:
>
>> Thank you again, I understand security implications but objective is to
>> make it work for Edge, I have control over native methods, getClipBoardata
>> and setClipboardData(String data)  which are native methods in java. The
>> code which I have pasted above is working fine with IE browser, but not
>> with modern browsers. So can you help me with the code/pointers which can
>> replace above code and work for Edge,Chrome. Thanks.
>>
>> On Thursday, 20 October 2022 at 14:52:22 UTC+5:30 [email protected] wrote:
>>
>>> Well if I remember correctly it is not supposed to access the clipboard
>>> directly because that would be a huge security issue.
>>>
>>> Consider the following scenario. You copy / paste your password for your
>>> bank somewhere. Then you go to a random webpage. If the javascript of this
>>> webpage that runs on your computer/browser could access
>>> (getClipboardData()) your clipboard your bank password would be compromised.
>>>
>>> So you can only access the clipboard from inside an event handler that
>>> handles the "copy" event aka Ctrl+C.
>>>
>>> The necessary details to access the data differ from IE and so I have
>>> posted examples.
>>>
>>> I do not know why your code does not compile. I think native methods are
>>> not checked so they tend to give NULL errors during runtime. If that is
>>> your case then caniuse is your friend.
>>>
>>>     Vassilis
>>>
>>>
>>>
>>> On Thu, Oct 20, 2022 at 11:12 AM Pramod Patil <[email protected]>
>>> wrote:
>>>
>>>> Hi Thanks for your response,
>>>> on both front at GWT and Javascript  I am at beginners level, will it
>>>> be possible to have modification in below function, which will
>>>> support copyclipboard functionality with Microsoft Edge. I tried
>>>> navigator.clipboard.writeText() but code is not getting compiled.
>>>> public static native String getClipboardData()/*-{
>>>> i*f($wnd.clipboardData && clipboardData.setData){*
>>>> *return $wnd.clipboardData.getData('Text');*
>>>> }
>>>>
>>>> On Thu, Oct 20, 2022 at 12:36 PM Vassilis Virvilis <[email protected]>
>>>> wrote:
>>>>
>>>>> For non IE browsers I have this:
>>>>>
>>>>>             // attach event listeners
>>>>>             // copy - cut - paste handlers
>>>>>             ((Element) Js.cast(getElement())).addEventListener("copy",
>>>>> copy_li);
>>>>>             ((Element) Js.cast(getElement())).addEventListener("cut",
>>>>> cut_li);
>>>>>             ((Element)
>>>>> Js.cast(getElement())).addEventListener("paste", paste_li);
>>>>>
>>>>> where (Element) is elemental2.dom.Element
>>>>>
>>>>> copy_li is something like this:
>>>>>
>>>>>         final elemental2.dom.EventListener copy_li = new
>>>>> elemental2.dom.EventListener() {
>>>>>             @Override
>>>>>             public void handleEvent(elemental2.dom.Event evt) {
>>>>>                 final ClipboardEvent event = Js.cast(evt);
>>>>>                 copy(event);
>>>>>             }
>>>>>         };
>>>>>
>>>>> where ClipboardEvent is elemental2.dom.ClipboardEvent
>>>>>
>>>>> I need a copy function because I reuse it in the "Cut" functionality
>>>>> also.
>>>>>
>>>>> and finally copy is something like this
>>>>>
>>>>>    private void copy(ClipboardEvent event) {
>>>>>         if (!hasData()) {  // <-- hasData() is your application
>>>>> specific function
>>>>>             return;
>>>>>         }
>>>>>
>>>>>         // do application stuff get/iterate and finally get the data
>>>>> in a String form somehow...
>>>>>         final String data = getData();  // application specific
>>>>>
>>>>>         event.clipboardData.setData("text/plain", data);
>>>>>         event.preventDefault();
>>>>>     }
>>>>>
>>>>> Similarly the paste evenListener:
>>>>>
>>>>>         final elemental2.dom.EventListener paste_li = new
>>>>> elemental2.dom.EventListener() {
>>>>>             @Override
>>>>>             public void handleEvent(elemental2.dom.Event evt) {
>>>>>                 final ClipboardEvent event = Js.cast(evt);
>>>>>                 final String data =
>>>>> event.clipboardData.getData("text/plain")
>>>>>                 event.preventDefault();
>>>>>                 if (data == null)
>>>>>                     return;
>>>>>
>>>>>                 // now you need somehow to propagate data to the
>>>>> interesting parties (methods, classes etc)
>>>>>                 // I am using the EventBus from GWT
>>>>>                 getEventBus().fireEvent(new PasteEvent(data));
>>>>>             }
>>>>>         };
>>>>>
>>>>> Hope that helps
>>>>>
>>>>>      Vassilis
>>>>>
>>>>> On Thu, Oct 20, 2022 at 9:18 AM Pramod Patil <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> Hi All,
>>>>>> In our GWT application we are using Java native method call for
>>>>>> Copytoclipboard functionality. Please refer below code
>>>>>>
>>>>>> public static native String getClipboardData()/*-{
>>>>>> if($wnd.clipboardData && clipboardData.setData){
>>>>>> return $wnd.clipboardData.getData('Text');
>>>>>> }
>>>>>> }
>>>>>> }-*/
>>>>>> public static native String setClipboardData(String data)/*-{
>>>>>> if($wnd.clipboardData && clipboardData.setData){
>>>>>> return $wnd.clipboardData.setData('Text',Data);
>>>>>> }
>>>>>> }
>>>>>> }-*/
>>>>>>
>>>>>> So above code is working fine with IE browser but not working with
>>>>>> modern browser. I know this is not GWT specific question, but I don't 
>>>>>> have
>>>>>> much knowledge with Javascript, so anyone who knows Javascript, please 
>>>>>> help
>>>>>> here.
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "GWT Users" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send an email to [email protected].
>>>>>> To view this discussion on the web visit
>>>>>> https://groups.google.com/d/msgid/google-web-toolkit/c7ebae01-b41f-440a-b4da-b6c1c91231e3n%40googlegroups.com
>>>>>> <https://groups.google.com/d/msgid/google-web-toolkit/c7ebae01-b41f-440a-b4da-b6c1c91231e3n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Vassilis Virvilis
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "GWT Users" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/google-web-toolkit/CAKbOjEybr2Kr5hEZ12tKccfMMuR6QZGazTZuZqRHVMd0bKg3ZA%40mail.gmail.com
>>>>> <https://groups.google.com/d/msgid/google-web-toolkit/CAKbOjEybr2Kr5hEZ12tKccfMMuR6QZGazTZuZqRHVMd0bKg3ZA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>
>>>>
>>>> --
>>>> Thanks and regards,
>>>>  Pramod Patil
>>>>  Contact +91-8975432800 <+91%2089754%2032800>
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "GWT Users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>>
>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/google-web-toolkit/CAAXS9-UatQ84dXiZeD7Q0TSXA9HT56UGZQLCzvZ4fFqbEoF23A%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/google-web-toolkit/CAAXS9-UatQ84dXiZeD7Q0TSXA9HT56UGZQLCzvZ4fFqbEoF23A%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>
>>>
>>> --
>>> Vassilis Virvilis
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "GWT Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/google-web-toolkit/f7386ec6-494b-4754-94dd-cbfbb42e8f22n%40googlegroups.com
>> <https://groups.google.com/d/msgid/google-web-toolkit/f7386ec6-494b-4754-94dd-cbfbb42e8f22n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
> Vassilis Virvilis
>
> --
> You received this message because you are subscribed to the Google Groups
> "GWT Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-web-toolkit/CAKbOjEzshqm%2Bs-SUOZuuqSSH-2AR_T9nmcZ9O%2BK7Lcxoy-_R-A%40mail.gmail.com
> <https://groups.google.com/d/msgid/google-web-toolkit/CAKbOjEzshqm%2Bs-SUOZuuqSSH-2AR_T9nmcZ9O%2BK7Lcxoy-_R-A%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Thanks and regards,
 Pramod Patil
 Contact +91-8975432800

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit/CAAXS9-VcTJkn5um-JvGQDjptot2E271GQeUD0ReE6LbKLhF0AQ%40mail.gmail.com.

Reply via email to