Stuck with opend window (DOM)

N

Nicholas

Hello,

I'm new in Javascript and it seems I'm a bit stuck so if someone can help.
The problem is 4th button / function. I dont know how to talk to the opend
window, the thing with focus i wrote doesen't work so i didn't wrote code
for randomizeing location (this i know how to do).

Did i do something wrong?

window.opener works fine form the child window is there something similar
for control from parent window?

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function op(a,b)
{
window.open('first.html', 'first', 'width='+a+',height='+b);
}
function rresize()
{
var v = screen.width;
var h = screen.height;
var vx = Math.floor(Math.random()*1000);
var hx = Math.floor(Math.random()*1000);
if( vx > v){vx = v;}
if( hx > h){hx = h;}
op(vx,hx);
}
function rmove()
{
window.first.focus();
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<input type="button" value="open new window 350 x 200"
onClick="op(350,200)"></br>
<input type="button" value="open new window 1/2 width and height of screen"
onClick="op(screen.width/2,screen.height/2)"></br>
<input type="button" value="open new window radnom size"
onClick="rresize()"></br></br>
<input type="button" value="focus and random move opend window"
onClick="rmove()"></br>
</BODY>
</HTML>

Thank you!
 
L

Lee

Nicholas said:
Hello,

I'm new in Javascript and it seems I'm a bit stuck so if someone can help.
The problem is 4th button / function. I dont know how to talk to the opend
window, the thing with focus i wrote doesen't work so i didn't wrote code
for randomizeing location (this i know how to do).

Did i do something wrong?

Yes, you tried guessing what might work, instead of reading a manual.


<script type="text/javascript">

var firstWindow;

function op(a,b)
{
firstWindow=window.open('first.html', 'first', 'width='+a+',height='+b);
}

function rresize()
{
var v = screen.width;
var h = screen.height;
var vx = Math.floor(Math.random()*1000);
var hx = Math.floor(Math.random()*1000);
if( vx > v){vx = v;}
if( hx > h){hx = h;}
op(vx,hx);
}

function rmove()
{
if(firstWindow) {
firstWindow.focus();
}
}

</SCRIPT>


--
 
A

ASM

Nicholas a écrit :
Hello,

I'm new in Javascript and it seems I'm a bit stuck so if someone can help.
The problem is 4th button / function. I dont know how to talk to the opend
window, the thing with focus i wrote doesen't work so i didn't wrote code
for randomizeing location (this i know how to do).

Did i do something wrong?

window.opener works fine form the child window is there something similar
for control from parent window?

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function op(a,b)
{
window.open('first.html', 'first', 'width='+a+',height='+b);

you have to give a JS name to your popup :

myPopUp = window.open('first.html','first','width='+a+',height='+b);
}
function rresize()
{
var v = screen.width;
var h = screen.height;
var vx = Math.floor(Math.random()*1000);
var hx = Math.floor(Math.random()*1000);
if( vx > v){vx = v;}
if( hx > h){hx = h;}
op(vx,hx);
}
function rmove()
{
window.first.focus();

myPopUp.focus(); // window is de facto
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top