Page 1 of 1
PHP/JS Problem
Posted: Fri Jun 25, 2004 2:24 pm
by Joe
Is there any way in PHP or javascript to open a new window when the user clicks on the link. I have tried window.open() but it just opens the new window when I refresh the browser rather than waiting for the linked to be clicked first.
Any help appreciated.
Joe
Posted: Fri Jun 25, 2004 2:31 pm
by ol4pr0
Something i have used.. with some modification you could have ure result.
This will open up a new window.. when loading up this page.
Code: Select all
<script language="JavaScript">
<!--
function openWindow(theURL)
{
var cadena;
var ancho, alto;
ancho = screen.availWidth - 10;
alto = screen.availHeight - 50;
cadena = 'left=0,top=0,border=0,status=yes,scrollbars=no,toolbar=no,menubar=no,location=no,resizable=yes,' + 'width=' + ancho + ',height=' + alto;
window.open(theURL, "_blank", cadena);
//window.open(theURL, "SITENAME WEBSERVER", cadena);
}
function getCookie(Name)
{
var search = Name + "="
if (document.cookie.length > 0)
{ // if there are any cookies
offset = document.cookie.indexOf(search)
if (offset != -1)
{ // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset)
// set index of end of cookie value
if (end == -1)
end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
}
}
function CargaString()
{
window.status = "Welcome to SITENAME";
var yourname = getCookie("USERNAME");
if (yourname != null)
{
//Ha cargado el sitio previamente
// meaning cookie did got set..
Tiempo = setTimeout("openWindow('togopage.php')", 100);
}
else
{
//No ha cargado el sitio previamente
// meaning cookie didnt got set "GO BACK TO START ;-) "
register("USERNAME");
Tiempo = setTimeout("openWindow('if?togopage2.php')", 100);
}
}
//-->
</script>
<!--<script language="JavaScript" src="lib_click.js"></script>-->
</head>
<body onload="CargaString();" bgcolor="#FFFFFF" marginwidth="0" marginheight="0" topmargin="0" leftmargin="0">
</body>
Posted: Fri Jun 25, 2004 2:45 pm
by Joe
Well I want it so the window opens when I click the link. Your above code is just the same as window.open() except more complicated. Is there any other way?
Posted: Fri Jun 25, 2004 2:47 pm
by ol4pr0
onClick !
Code: Select all
<a href="javascript:void(0)" onClick="window.open('yourpage.php','mywindow','width=500,height=400,toolbar=no,menubar=no,')">
Posted: Fri Jun 25, 2004 2:51 pm
by Joe
YAY thanks man it worked a treat.
Cheers