2

i have following dart code:

@override
void attached() {
  document.onCopy.listen(_onCopyHandler);
}

void _onCopyHandler(Event event) {
  // Here i'd like to access event.clipboardData but it 
  // does not work for Firefox using Dart code so i need to
  // get access to underlying javascript event object
}

i've already tried following without any success on Firefox (for Chrome it worked):

var jsEvent = new JsObject.fromBrowserObject(event);

as soon as i'll have a reference to JsObject i know how to call the method, i just need to get an access to that reference.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Marek Suscak
  • 1,086
  • 10
  • 25
  • i've forgotten to mention that it does not work in Firefox due to this bug: https://code.google.com/p/dart/issues/detail?id=19368 – Marek Suscak Jul 02 '14 at 18:28
  • Why did `JsObject.fromBrowserObject(event)` not work? Can you add the error message or some additional info to your question? – Günter Zöchbauer Jul 02 '14 at 18:45
  • 1
    If `fromBrowserObject` doesn't work you could do the registering of the event handler in JavaScript already (and pass a JS method as handler) and then call Dart from this JS event handler method. – Günter Zöchbauer Jul 02 '14 at 18:47
  • well, as soon as i did this: void _onCopyHandler(Event event) { var jsEvent = new JsObject.fromBrowserObject(event); // some code here event.preventDefault(); } i've got following error in Firebug's console (in chrome this exact code works without error): TypeError: J.getInterceptor$x(...).preventDefault$0 is not a function and jsEvent['clipboardData'] is undefined so i am unable to access it in Firefox, in Chrome it works as well – Marek Suscak Jul 02 '14 at 20:09
  • anyway how can i call dart instance method from javascript? i know how to call javascript function from Dart but not in the opposite way – Marek Suscak Jul 02 '14 at 20:45
  • the Answer to http://stackoverflow.com/questions/22351766 shows an example. This could be useful too http://stackoverflow.com/questions/21664092, http://stackoverflow.com/questions/15669163 – Günter Zöchbauer Jul 02 '14 at 22:17
  • `fromBrowserObject()` should work for this scenario, can you file a bug with an example I can look at? If that's failing, then another option is to write a JS function that gets the clipboard data and call that via js-interop. 19368 needs to get fixed though. – Justin Fagnani Jul 03 '14 at 04:42
  • ok i filed a bug, could you please take a look? the example is attached: https://code.google.com/p/dart/issues/detail?id=19816 – Marek Suscak Jul 03 '14 at 08:43

0 Answers0