jeudi 2 août 2018

Javascript: Global Child Window by Using function

I have two functions in my program. One of them, funct1() create and initialize a new window by using window.open(). Other function, funct2() is called when an event happen in the new window. funct2() write some text on the new window.

The problem is I can't access handle or reference of the new window from funct2(). My codes look like this:

var newWindow;
funct1(){
newWindow = window.open("","");} `
funct2(){
newWindow.document.write("Hello World");}

The program crashes as soon as it attempts to write newWindow.I used console and findout that newWindow is null in funct2(). Is there a way to access newWindow reference in funct2() and modify the newWIndow?

There is a restriction here. funct2() must not used any parameter passing. Also, funct1() must initialize the newWindow upon a call.

Aucun commentaire:

Enregistrer un commentaire