Today I needed to pass a pop-up some PHP variables and I couldn’t remember how to do it. So after thinking about it for a few minutes and Googling some really convoluted examples, I came up with an easy and simple solution. I was making a pop-up for people’s bio’s so this example will use the names I used for my original task.
Somewhere in the body of your main page put in this function:
<script type=”text/javascript”>
<!–
function Pop(f) {
window.open( f, “popUpWindow”, “status = 0, scrollbars = 1, height = 400, width = 400, resizable = 1″ );
}
//–>
</script>
This function takes 1 argument, f, which is the filename. All the size, scrollbars, and additional popup variables at the end are optional.
To call the function and pass it variables, do this:
<a href=”#” onclick=”Pop(’bio.php?firstname=Tom&lastname=Thumb’)”>Tom Thumb’s bio</a>
In bio.php, you can use PHP’s $_REQUEST or $_GET to read in or spit out all the variables, like so:
<?
foreach ($_GET as $varname => $data) {
echo $varname.”: “.$data.”<br />”;
}
?>
If this has helped you, or you have a question or suggestion for improvement, leave a comment.