delayed window close

They have: 3 posts

Joined: Sep 2010

I have been researching this all day, and am still getting the same message asking if I want to allow the window to close. It's rather annoying.

Here is my scenario. I have a contact link where visitors can fill out a form and "send" and the email comes to me. The visitor is sent to a "thank you" Basic PHP.

What I want to do is have the window close automatically after about 30 seconds. It keeps giving me the error message when I test it. My code is below. Any help would be greatly appreciated.

<?php
        $to
="myemail";

       
$subject=$_REQUEST["Subject"];
       
$gender=$_REQUEST["Gender"];
       
$age=$_REQUEST["Age"];
       
$comment=$_REQUEST["textarea"];
       
$message="Gender: ". $gender . "\r\n" . "Age: " . $age . "\r\n" . "Comment: " . $comment;
       

       
$email_header = "X-Mailer: PHP/" . phpversion();
       
mail($to, $subject, $message, $email_header);
?>

function openWin()
{
X=window.open("","","width=200,height=100");
X.document.write("This is 'X'");
}

function closeWin()
{
X.close();
}
setTimeout('self.close();',30000);

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

As far as I'm aware, this is not something you can have full control over. Closing a window should be entirely up to the user - not the web developer.

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

It is possible to close the browser window in most browsers, but the browser will usually prompt the user before it happens. Like Renegade says, it's not really up to you.

They have: 3 posts

Joined: Sep 2010

Thank you for your responses.
maybe it would be better just to redirect them then? Is there a way I can redirect them to my homepage?

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

You can redirect in Javascript by changing the location of the window:
setTimeout('window.location = "http://yourwebsite.com"',30000);
Or in PHP

<?php
header
("Location: /index.php");
exit(
0);
?>

Make sure you don't output anything on the page before you call header(). That will trigger an error.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.