PDA

View Full Version : dynamic pop-up window


registered_memb
11-03-2005, 02:06 AM
Hi,

could someone please help with this:

The following js-php system doesn't work.
Actually, when i run popup.php i get 3 links, but after clicking on them nothing happens.

popup.php
<html>
<head>
<title>Listing 15-4</title>
<SCRIPT language="Javascript">
<!—
// declare a new JavaScript variable
var popWindow;
// declare a new function, newWindow
function newWindow(winID) {
// declare variable winURL, setting it to the name of the PHP file
// and accompanying data.
var winURL = "window.php?winID=" + winID;
// If the popup window does not exist, or it is currently closed,
// open it.
if (! popWindow || popWindow.closed) {
// open new window having width of 200 pixels, height of 300
// pixels, positioned
// 150 pixels left of the linking window, and 100 pixels from the
// top of the linking window.
popWindow = window.open(winURL, 'popWindow', 'dependent,width=200,height=300,left=150,top=100');
}
// If the popup window is already open, make it active and update
// its location to winURL.
else {
popWindow.focus();
popWindow.location = winURL;
}
}
//—>
</SCRIPT>
</head>
<body bgcolor="#ffffff" text="#000000" link="#808040" vlink="#808040" alink="#808040">
<a href="#" onClick="newWindow(1);">Contact Us</a><br>
<a href="#" onClick="newWindow(2);">Driving Directions</a><br>
<a href="#" onClick="newWindow(3);">Weather Report</a><br>
</body>
</html>

window.php
<html>
<head>
<title>Popup Window Fun</title>
</head>
<body bgcolor="#ffffff" text="#000000" link="black" vlink="gray" alink="#808040" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<?
// Include file specified by input parameter
INCLUDE("$winID.inc");
?>
</td>
</tr>
<tr>
<td>
<a href="#" onClick="parent.self.close();">close window</a>
</td>
</tr>
</table>
</body>
</html>

1.inc
<table>
<tr>
<td>
<h4>Contact Us</h4>
<ul>
<li>email: <a href="mailto:john@smith.com">john@smith.com</a>
<li>phone: (555) 888 4444
<li>mobile: (555) 555 5555
</ul>
</td>
</tr>
</table>

2.inc
<table>
<tr>
<td>
<h4>Driving Directions</h4>
<ol>
<li>Turn left on 1st avenue.
<li>Enter the old Grant building.
<li>Take elevator to 4th floor.
<li>We're in room 444.
</ol>
</td>
</tr>
</table>

3.inc
<table>
<tr>
<td>
<h4>Weather Report <?=date("m-d-Y");?></h4>
<b>Today:</b> Brrr... Brisk, with blowing and drifting snow.<br><br>
<b>Tonight:</b> Winter Weather Advisory. 7-10 inches snow expected.
</td>
</tr>
</table>


I have pop-up blocking(firefox) disabled.


Thank you in advance :thumbsup:

Pyth007
11-03-2005, 01:03 PM
The newer releases of php no longer automatically translate passed variables into local ones, unless you go into the ini file to change it (this is done for security reasons).

In window.php, instead of having INCLUDE("$winID.inc"); try INCLUDE("{$_GET['winID']}.inc"); which uses the $_GET[] super-global associative array and your variable name as the key to retrieve the value (actually, if you get an error, its probably because inside a string, the single-quotes around the variable name are not needed--I'm always forgetting php's rules about when to use quotes). Alternatively, you could assign a local variable to the passed value:
$myIDNumber = $_GET['winID'];
include ("$myIDNumber.inc");but if you do do it this way, it's best not to use the same variable name... again for security reasons.

registered_memb
11-04-2005, 01:17 AM
Thanks 007,

I have register_globals on my php turned On (yes i know, please don't flame me for that) just for learning purposes, so i can use simple variable names.

Well, the problem was a strange "—" sign (in the HTML comment line <!—) which i pasted from pdf tutorial.

After i replaced that with "--" everything goes fine.


Greets :thumbsup:

Pyth007
11-04-2005, 01:01 PM
Yeah... those small gotcha's are the worst! I had a piece of code, once, that I kept going over trying to find where I had an error. After about a week of searching, I finally found out that I had accidentally used a colon : instead of a semi-colon ; ... and I probably wouldn't have caught it except that I had printed out the script and the printer's resolution was better than the monitor's (crappy monitor from my pentium 1; about 10 years old)