|
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=javascript penCenterWin("home.html",754,500)> <font color="#000000">Centered
Window</font></a> </p>
</div>
</body>
</html>
|
|
|
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.
|
|
|
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?
|
|
|
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.
|
|
|
|
|
|
|
|
|
|