How do I call a Function in window2 from the page I opened it from window2?

I and trying to open a window with the window.open code,

var myWindow = window.open(url , name, details);

and then I want to execute a function in that window after it loads.

var myWindow = window.open(url , name, details);
myWindow.doSomething();

The Idea is to have it both triggered by a button, HTML based.

I have just been rewriting it in different ways, and thus far nothing seems to work. Any input would be appreciated.