From the main page I would like to open a child window and from the child window I would like to open a another window. how is it possible?
I have tried the below code and its not working.
<script type='text/javascript">
function click1(){
var win1=window.open();
win1.document.write("first window");
var windowHTML ='<input type="button" value="click" onclick="click2()" />';
win1.document.write(windowHTML);
}
function click2(){
var win2=window.open();
win2.document.write("seccond window");
}
<input type="button" value="click1" onclick="click1()" />
Two options:
1. Use
openerin the childChange
to
openerin the child window will be a reference to your main window, and since you’re using global functions, they can be called via that reference (assuming that there are no SOP issues).2. Put the code in the child
Alternately, you can put the code you want to trigger in the child window by writing a
scripttag to it (either one that contains inline JavaScript, which is a bit dodgy, or one that references an external file, which would be better).FWIW, I’d recommend stepping back and asking whether you really need to use multiple windows rather than sticking to one window and doing “virtual” windows via
divs and such.