2

I can get parent window name in Javascript, and don't know how to do it in Dart. I have tried to down cast window.opener to window in Dart, but it throw exception. According html5.1 nightly, should we expect it implemented as window basic attribute?

//js version:
window.opener.name
//dart version:
(window.opener as ?).name
kao peter
  • 86
  • 1
  • 5

2 Answers2

1

For a popup window.opener can be used and for an iframe window.parent. Both return a _DOMWindowCrossFrame which do not support name as they implement WindowBase. That's also the reason why you can't cast to window. You should use postMessage to communicate and exchange information.

See also this implementation note: Its fields and methods can only be accessed via JavaScript.

Robert
  • 5,484
  • 1
  • 22
  • 35
1

An alternative approach is to use dart-js-interop

import 'dart:js' as js;

print(new js.JsObject.fromBrowserObject(
    js.context['window'])['opener']['name']);

There is currently no way in Dart. Access to the windows object is intentionally denied for security reasons. According to comments on related bug reports they consider changing it because it can be worked around using dart-js-interop anyway.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567