I'm making a form for an e-commerce site for the user to request a PDF about an item. The form works fine and sends the user to the "Thanks" page. On the thanks page I have jQuery set an interval to close the window after 5 seconds. But it does not work, neither does embedding the close command in a link. However, the interval will work if the "Thanks" page opens in a new tab.
Here is the code in the php file (gets called after form has been successfully submitted).
/* Results rendered as HTML */
$theResults = <<<EOD
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Thanks</title>
<script type="text/javascript" src="css/00000001/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
//wait a few seconds and close the window
setInterval(function()
{
window.close();
}, 5000);
});
</script>
<style type="text/css">
body{
background-color: transparent;
margin: auto auto auto auto;
border: none;
}
#general-copy{
background-color: transparent;
margin: -5px auto auto 0px;
position: absolute;
width: 300px;
height: 350px;
padding: 0px 15px 15px 15px;
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 14px;
font-style: normal;
font-variant:normal;
font-weight:100;
text-align: justify;
z-index: 3;
}
</style>
</head>
<body><br /><br />
<div class="lettertext">
Thank you for your request.<br />
We will email you a pdf all about $item2Field.
<br><br>
<p style="font-size: 10px;">This window should close itself in 5 seconds.<br>
If it doesn't please click <a href="javascript:window.close()">here</a> to return to the site.
</p>
</div>
</body>
</html>
EOD;
echo "$theResults";
?>
If you wish to see this running live you can try it out here.