Читать книгу PHP Programming for Beginners. Key Programming Concepts. How to use PHP with MySQL and Oracle databases (MySqli, PDO) - Sergey D Skudaev - Страница 19

Pass $_GET Parameters to a Modeless Popup

Оглавление

Here I’ll show you how to create a modeless popup to pass $_GET parameters from a parent page to the popup page. PHP and JavaScript are used to make this possible. First the JavaScript modelessparam function creates a modeless popup. Then you can pass parameters in the URL and read them in the popup page.

This is a script for the main page.

parent.php

<!DOCTYPE html>

<html lang=“en”>

<html>

<head> <title> Pass params to modeless popup </TITLE>

<?php

$param1=“Hello There!”;

$param2=“Hi World!”;

?>

<script>

function modelessparam (url, width, height) {


eval (‘window. open (url,””, “width='+ width + ‘px, <=>

height='+height+‘px, resizable=1, scrollbars=1”)”)

}

</script>

</head>

<body>

<p align=“center”> <input type=“button” name=“greeting” <=>

value=“Open Popup” <=>

onClick=“javascript: modelessparam (<=>

“http://yourdomain/popup/popup.php?<=>

param1= <? echo $param1;?> <=>

&param2= <? echo $param2;?>”, 300, 200)”> </p>

</form>

</body>

</html>


The bold code must be one line without breaks. The <=> is used as a carry-over sign only.

This is a script for a popup page:

popup.php


<!DOCTYPE html>

<html lang=“en”>

<html>

<head>

<title> Popup with params from parent window </title>

<?

if (isset ($_GET [‘param1”]))

$param1 =$_GET [‘param1”];


if (isset ($_GET [‘param2”]))

$param2 =$_GET [‘param2”];

?>

</head>

<body>

<?php

print (” <p style=“align: center; font-size:40px; <=> color:#000;">”.

$param1.” </p>”);

print (’<p style=‘align: center; font-size:50px; <=>

color: #000;">”. $param2.”</p>”);

?>

</body>

</html>


Output: modeless window popup with text

Hello There!

Hi World!

PHP Programming for Beginners. Key Programming Concepts. How to use PHP with MySQL and Oracle databases (MySqli, PDO)

Подняться наверх