469,329 Members | 1,326 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,329 developers. It's quick & easy.

Stuck with opend window (DOM)

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!
May 11 '07 #1
2 1415
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>
--

May 11 '07 #2
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+',heig ht='+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
}
//-->
</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!


--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Contact : http://stephane.moriaux.perso.wanadoo.fr/contact
ASM = Aimable Stéphane Moriaux = Amateur Sasseur Merdouilles
May 11 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jawahar Rajan | last post: by
1 post views Thread by Andi B | last post: by
6 posts views Thread by news.versatel.de | last post: by
29 posts views Thread by wayne | last post: by
5 posts views Thread by Hemanth | last post: by
6 posts views Thread by Luke Matuszewski | last post: by
26 posts views Thread by yb | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.