Open a new window and get its location after loading

Issue

I am using this code to open a new window:

Window w = window.open('example2.com', 'example2'); // Consisder than my domain
                                                    // is example1.com

This part of code works ok and succesfully opens a new window. Than i am trying to call my function after loading finishes.

w.onLoad.listen(locationGetter);

This is a code of locationGetter() function:

locationGetter(Event e) {
  Location currentLocation = w.location;
  currentHref = currentLocation.href; // currentHref is var defined
}                                    // in main() function

But this code doesn’t work well. Every time when I run my script both currentLocation and currentHref is null. At the beginning i thought that problem was in onLoad event, so i tried to call w.location exacly after opening a window:

Window w = window.open('example2.com', 'example2');
Location currentLocation = w.location; // still null

I am pretty sure that both Window and WindowBase has location property. Please help me with my problem or provide alternative solution of this task.

Solution

I don’t think this is a Dart issue.

Seems you run into this
http://blog.carbonfive.com/2012/08/17/cross-domain-browser-window-messaging-with-html5-and-javascript/

CORS prevents accessing windows of other domains, you can use postMessage instead.

Answered By – Günter Zöchbauer

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *