5

I'd like to open a new window, this window has a list of objects, and these objects should be filtered based on a selection from the previous window. I figured I can filter the list through a function, but how do I run said function?

This is what I am able to do:

var popup = window.open('pageURL');
    $(popup.document).ready(function() {
        // this is where function should be
        popup.alert('HelloWorld');
    });

But how do I change the alert to a function?

If I have a function on my other app , function test() { alert('HelloWorld'}; How do I run this function from my first app?

Swapping popup.alert('HelloWorld'); with popup.test(); did not work.

sch
  • 1,368
  • 3
  • 19
  • 35

3 Answers3

0

You need the reference to the window opened to call functions in the new window, like:

var oNewWindow = window.open("new.window.url", "mywindow");
oNewWindow.onload = function(){oNewWindow.window.newWindowFunction();};
  • i have that `popup.test()` where `popup` is the reference and `test()` is the function, does not work, error: `object doesn't support property or method` – sch Jul 06 '16 at 10:56
0

I ended up with this solution

var popup = window.open('http://s234-0057/actiontracker/SiteAssets/Avvik/html/app.aspx');

var readyStateCheckInterval = setInterval(function() {
    if (popup.document.readyState === "complete") {
        clearInterval(readyStateCheckInterval);
        popup.test();
    }
}, 50);

Where I check if the popup window is ready, and when it is, cancel check and run function. Solution is from top answer on this question, by @this.lau_

Community
  • 1
  • 1
sch
  • 1,368
  • 3
  • 19
  • 35
0

You can write it like this:

function myFunction(){
    alert('HelloWorld');
}

var popup = window.open('pageURL');
$(popup.document).ready(function() {
    popup.eval(myFunction + "");
    popup.myFunction();
});

myFunction in file that contains this code will run in page with pageURL address.

erfanilaghi
  • 206
  • 3
  • 12