codetoad.com
Home||ASP|ASP.Net|C++/C#|DHTML|HTML|Java|Javascript|Perl|VB|XML||CodeToadPlus!||Forums||RAM
Search Site:
Search Forums:
Pop up window that centres on the screen - problems robskinn at 16:27 on Tuesday, September 09, 2003

Hi, I am trying to put a jumble of code together to allow a pop-up window to centre on the screen, could anyone help me please :-)

This is the code I have, as you can see I have a pop-up window script and a centring window script and am using an onLoad function, I don't know how to combine them though? Thanks

 The full html code:  



<html>
<head>

<title>Fruehauf</title>

<script language="JavaScript">
<!--
self.moveTo(0,0)
self.resizeTo(screen.availWidth,screen.availHeight)
//-->
</script>


<script language="JavaScript">
function openCenterWin(url,theWidth,theHeight){
var theTop=(screen.height/2)-(theHeight/2);
var theLeft=(screen.width/2)-(theWidth/2);
var features=
'height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft+",scrollbars=no";
theWin=window.open(url,'',features);
}
</script>


<script>
var theURL = 'home.html';
var width = 754;
var height = 500;
function popWindow() {
newWindow = window.open(theURL,'newWindow','toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,location=no,width='+width+',height='+height);
}
</script>


<script language="JavaScript">
<!--
intMilSec = (10 * 1000);
function fCloseWindow() {
window.close();
}
//-->
</script>


</head>

<body bgcolor="E6E6DC" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="setTimeout('fCloseWindow()',intMilSec),popWindow()" scroll="auto" link="#EFE7DF" vlink="#EFE7DF" alink="#FF8000">
<div align="center">
<p></p>
<p></p>
<p></p>
<p><a href="javascript:popWindow()"><font color="#000000">Click here</font></a>
</p>


<p><a href=javascriptpenCenterWin("home.html",754,500)> <font color="#000000">Centered
Window</font></a> </p>
</div>
</body>
</html>


Re: Pop up window that centres on the screen - problems robskinn at 10:42 on Wednesday, September 10, 2003

Thanks for the code it combines the two separate versions well - I still need to find a way to automatically open the pop-up as the mother window opens - I have tried to use an onLoad behaviour but it does not seem to work?

Any suggestions? Many thanks.

Re: Pop up window that centres on the screen - problems robskinn at 16:44 on Wednesday, September 10, 2003

Fantastic - works very well, thanks.

You may have noticed I have some script which closes the parent window after 10 seconds from being launched - is there any way which I can leave a 2 second gap before the pop-up window launches?

Re: Javascript setTimeout to pause before popup window is opened Troy Wolf at 17:08 on Wednesday, September 10, 2003

You just need to use the javascript setTimeout() function.

Copy & Paste the code below as a new HTML file, then open in browser to see it run.
<script language="javascript">
function WinPop(winName, winSrc, winWidth, winHeight, scroll, menubar, toolbar)
{
if (!scroll) { scroll = "no" }
var winLeft = (screen.width-winWidth)/2;
var winTop = (screen.height-winHeight)/2;
wname=window.open(winSrc, winName, "menubar="+menubar+",toolbar="+toolbar+
",resizable=yes,scrollbars="+scroll+",width="+winWidth+
",height="+winHeight+",top="+winTop+",left="+winLeft);
}
function Annoy()
{
WinPop("test","http://www.shinysolutions.com",650,400,0,0,0);}
function LoadTrigger()
{
// 1 second = 1000
setTimeout("Annoy()",5000);
}
window.onload = LoadTrigger;
</script>
<body>
Shiny Solutions homepage will open in a popup in 5 seconds.
</body>


If I'm helping you build a site that pops up multiple ad windows, shame on me! (Sorry, CodeToad! One or two popup ads is OK, but after navigating around CodeToad for a few minutes, I end up with 8,9,10 ad windows open! Maybe have code that only pops 2 ad windows. After that, open new ad content into the existing windows. Or only load new ad windows if the user closes the original 2.) My $0.02.
Troy Wolf: site expert
SnippetEdit Website Editor









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
matrix addition
Re: Storing data from HTML to Excel or TXT
Re: function within loop problem
Re: Ô‡´ò¥¯¥é¥Ö¤Ï ¥Æ©`¥é©`¥á¥¤¥É£ò£±£±¥¢¥¤¥¢¥ó ¤Î£··¬ ¤Ç¤¹
Re: Replace
Re: タイトリスト AP2アイアン 712�情�
Re: SMS from Perl using HTTP request
Re: Charl Schwartzel
Re: Adhyayan - Annual Student Conference and Online Coding Festival


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


Copyright codetoad.com 2001-2013