PDA

View Full Version : Positioning a popup window on the screen?


Thooms
03-21-2005, 05:23 PM
Ok, I had a popup with this script:

<SCRIPT LANGUAGE="JavaScript">
<!--
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=700,height=640');");
}
// -->
</script>

To be opened with this link:

<a href="javascript:popUp('popup.htm')"></a>

..

The solution was to add:

left=xxx,top=xxx

.. to the script, replacing xxx with the amount of pixels from the left/top of your screen, you want the top left corner of your popup to be when you open it...

e.g:

<SCRIPT LANGUAGE="JavaScript">
<!--
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=700,height=640,left=300,t op=100');");
}
// -->
</script>

.. If I wanted to have the top left corner positioned 300 pixels from the left of my screen and 100 pixels from the top of my screen, when I opened it...

:D

_Aerospace_Eng_
03-22-2005, 11:31 AM
GRR! Why did you delete it? You could have posted the solution so others with the same problem could have benefited from it, this forum to help others also not just yourself! :mad: Who knows we may be able to provide a better solution...

Thooms
03-24-2005, 11:51 AM
Sorry, I've just had some nasty experiences with other boards, that hated to have "unnecessary" topics.. Many boards, actually... :rolleyes:

.. But now, I've added the solution!

I'll remember to put it right away the next time! :D

_Aerospace_Eng_
03-24-2005, 02:24 PM
okay thats better but would u want the popup centered as well?

Thooms
03-24-2005, 03:06 PM
No, actually this was pretty much what I was looking for!

.. But, is there any way to center it, other than to fiddle with the numbers?

It would be nice to know, for future reference!

_Aerospace_Eng_
03-24-2005, 03:14 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Custom Windows</title>
<script type="text/javascript">
<!--
function openwin(url,wid,hgt){
sw=(screen.width-wid)/2;
sh=(screen.height-hgt)/2;
window.open(''+url+'','','width='+wid+',height='+hgt+',top='+sh+',left='+sw+'');
}
//-->
</script>
</head>

<body>
<a href="http://www.yahoo.com"
target="_blank"
onclick="openwin('http://www.yahoo.com','300','400');return false">Yahoo</a>
<a href="http://www.htmlforums.com"
target="_blank"
onclick="openwin('http://www.htmlforums.com','500','500');return false">HTMLForums</a>
<a href="http://www.google.com"
target="_blank"
onclick="openwin('http://www.google.com','200','200');return false">Google</a>
</body>
</html>