...

View Full Version : New popup window - how to make it in the center always?



2blaze
06-11-2007, 04:06 PM
Hello.

I need to carry out javascript which develope new window(open.window) This window must appear in the middle of bigger window along with size changing of bigger window small must be all the time in the middle of the bigger one
Please someone help me ;(

This is what i have now:

<HTML>
<HEAD>
<SCRIPT>
<!--
var okno;
// Opens new window
function otworz()
{
okno=window.open('', 'Wiadomosci', 'scrollbars,height=300,width=300');

}

</SCRIPT>
</HEAD>
<BODY onLoad="otworz()" onunLoad="zamknij()">
</BODY>
</HTML>


Please help me!

Regards Peter

Philip M
06-11-2007, 05:39 PM
Is this what you mean?

<HTML>
<HEAD>

<script type="text/javascript">
function openWin(url,wid,hgt)
{
sh = (screen.height - hgt) / 2;
sw = (screen.width - wid) / 2;
var newwin = window.open(url,'win','width='+wid+',height='+hgt+',top='+sh+',left='+sw+'');
if(newwin) newwin.focus();
return false;
}
</script>
</HEAD>

<BODY>
<a href="http://www.yoururl.com" onclick="return openWin(this.href,400,300)">Open New Window in Centre</a>

</BODY>
</HTML>


Please see the Posting Guidelines re silly thread titles. This thread title is not very helpful to anyone searching for this topic in the future.

2blaze
06-11-2007, 06:49 PM
yeah, sorry


Hm yes this small window opens in the centre but if you try to resize the bigger one, smaller remains in the same position. ;(

I am trying to make something with window.onresize event...but i cant ;(

glenngv
06-11-2007, 06:58 PM
What will happen if the user resizes the bigger window to make it smaller than that popup window?

2blaze
06-11-2007, 07:02 PM
yes good question ;)

It will be good when there will be min value of size(big window) ofcourse bigger than the smaller one.

2blaze
06-11-2007, 11:18 PM
http://popups.biz/

here is example

CaptainB
06-12-2007, 12:04 AM
http://javascript.internet.com/generators/popup-window.html

2blaze
06-12-2007, 12:11 AM
...this generator will not help...

CaptainB
06-12-2007, 12:13 AM
Why? It has a checkbox which says: "Should we center the window on screen?"

I guess that was what u were looking for?

EDIT: Or wait! Now I see it...sorry lol.

_Aerospace_Eng_
06-12-2007, 12:29 PM
On the popup pages add this in between the head tags.

<style type="text/css">
html, body {
margin:0;
padding:0;
height:100%;
}
</style>
<script type="text/javascript">
function f_clientWidth()
{
return f_filterResults
(
window.innerWidth ? window.innerWidth : 0,
document.documentElement ? document.documentElement.clientWidth : 0,
document.body ? document.body.clientWidth : 0
);
}
function f_clientHeight()
{
return f_filterResults
(
window.innerHeight ? window.innerHeight : 0,
document.documentElement ? document.documentElement.clientHeight : 0,
document.body ? document.body.clientHeight : 0
);
}
function f_filterResults(n_win, n_docel, n_body)
{
var n_result = n_win ? n_win : 0;
if (n_docel && (!n_result || (n_result > n_docel)))
n_result = n_docel;
return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
function moveIt()
{
sw = parseInt((screen.width - f_clientWidth()) / 2);
sh = parseInt((screen.height - f_clientHeight()) / 2);
window.moveTo(sw,sh);
}
window.onresize = function()
{
setTimeout("moveIt()",500);
}
</script>

2blaze
06-19-2007, 02:24 PM
OK i made it ;)

<html>
<head>
<script type="text/javascript">
<!-- <![CDATA[

rozmiarx = 300;
rozmiary = 200;
okno = open("about:blank","nazwa","width="+rozmiarx+",height="+rozmiary);

function wykonaj() {
if (!window.screenLeft) {
pozx = window.screenX;
pozy = window.screenY;
} else {
pozx = window.screenLeft;
pozy = window.screenTop;
}
var wysokosc = szerokosc = 0;
if (typeof(window.innerWidth)=='number') {
szerokosc = window.innerWidth;
wysokosc = window.innerHeight;
} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
szerokosc = document.documentElement.clientWidth;
wysokosc = document.documentElement.clientHeight;
} else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
szerokosc = document.body.clientWidth;
wysokosc = document.body.clientHeight;
}
pozycjax = pozx+szerokosc/2-rozmiarx/2;
pozycjay = pozy+wysokosc/2-rozmiary/2;
okno.focus();
okno.moveTo(pozycjax,pozycjay);
okno.focus();
setTimeout("wykonaj()", 300)
}
//window.onresize=wykonaj;
//window.onclick=wykonaj;
setTimeout("wykonaj()", 300)
// ]]> -->
</script>
<head>
<body>
</body>
<html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum