Determine if Pop-up was blocked

December 31, 2008 at 15:20:04
Specs: XP Pro SP3, na
I have a page (eventsubmit.php) which adds calendar events to my database, tells the user the event was added, then closes. Additionally, this page opens another page (email.php) which is used to further process data.

Currently, the eventsubmit.php page uses JavaScript "window.setTimeout('window.close()', 1000);" in the head to close the page, and a function which is called onload to open the email.php page.

The email.php page is prevented from opening on some of my user's computers by their pop-up blockers. Is there a way to determine if the email.php page was opened successfully, and if not, stop the eventsubmit.php page from closing and display a manual link to open the email.php page?

-Ryan Adams
Free Computer Tips and more:http://RyanTAdams.com

Paid Tech Support: Black Diamond


See More: Determine if Pop-up was blocked

Report •


#1
December 31, 2008 at 20:39:23
I'm not sure on the JS question, but I *may* have a straight php solution if I understood your problem right.

However, one pitfall is the embedded php code will only execute once, so you may have to reload the page depending on what you're up to in event submit script.

The upside, if it helps you out, is it doesn't rely on JS at all.

<?php

global $meta;
global $outp;

$meta = null;
$outp = null;

if(isset($_POST["evtsub"]) && $_POST["evtsub"] === "Calendar") {
$outp = "the event was added";
$meta = "<meta http-equiv='refresh' content='1; url=email.php'>";
}
?>
<html>
<head>
<?php if($meta != null && $outp != null) { echo $meta . "\n"; }?>
</head>
<body>
<?php if($outp != null) { echo $outp; } else {?>
<form action='<?php echo $_SERVER["PHP_SELF"];?>' method='post'>
<input name='evtsub' value='Calendar' type='submit'>
</form>
<?php }?>
</body>
</html>


Report •

#2
January 1, 2009 at 02:38:47
The simplest solution is to try and set a cookie on a pop-up page. If the cookie is set then you know the popup was not blocked.

Michael J


Report •

#3
January 1, 2009 at 11:06:03
What if I opened the popup, then used the "window.closed" property to check if the window as open. If "window.closed" is false, then the original page closes. If it is true, the original page stays open and displays a link to manually open the popup. Would that work?

-Ryan Adams
Free Computer Tips and more:http://RyanTAdams.com

Paid Tech Support: Black Diamond


Report •

Related Solutions

#4
January 1, 2009 at 21:30:19
Try it.

The problem with that approach (IMHO) is that it relies entirely on javascript. So, if the user has javascript disabled it won't work. By setting a cookie with javascript AND checking that cookie through the back end (PHP) you can kill two birds with one stone.

Michael J


Report •


Ask Question