Jump to content

popup window doesnot appear


bindiya

Recommended Posts

I have a html page where the email subscription is done. The partial php page does the processing of the fields and insert the value to the database.

If success,a popup window comes with a sucessmessage and html page should be displayed.

But this pop up window does not appear.

 

Pasting my code

 

subscribe.html
<html><body>
<form name='email_subscription' id='email_subscription' action='email_subscription.php' method='post' onsubmit="return verify_email();" >
                          <table width="312" bordercolor="#660000" border="1"   rules="none">
                           
                          <tr><td colspan='2'><p class="style28"><strong><span class="style22">Subscribe to our Newsletter</span></strong></p></td></tr>
                          <tr><td width="64"><p class="rvts16 style4 style14">   Email</p></td><td width="239"><input type='text' id='email_id' name='email_id' size="35" /></td></tr>
                          <tr><td colspan="2" style='text-align:right'><input type='submit' value=Subscribe name='subscribe' id='subscribe' onsubmit="return verify_email();" /></td></table></form></body></html>

email_subscription.php

<?php
include('config.php');

if(isset($_POST['subscribe']))
{

$email=$_POST['email_id'];
$date_time   = date('Y-m-d');
$query="insert into newsletter_emails(email_id,date_subscribed) values('$email','$date_time')";
$result=mysql_query($query);

?>

<script language="javascript"> window.open('SuccessMessage.php?fullview=Y','','height=300,width=525,resizable=yes,scrollbars=yes');</script>
<script> window.location='index.html'</script>
<?php
}
?>

SuccessMessage.php
<?php
echo "<h3><p></p><p></p><p></p><p></p><font color=#660000 ><center> Congratulations! You  successfully registered for the newsletter.</center></h3>";
?>


 

What will be the problem in this code.

Link to comment
Share on other sites

2 things:

 

1: Make sure you allow popups in your browser.  Most browsers these days even out-of-the-box by default will either disallow popups or prompt you for directions on what to do about it.  And that's just out-of-the-box.  Many users have ad-blocker or anonymous web surfing type addons/extensions for their browser that will also block or prompt when a popup occurs. 

 

You should consider that when making your script - most developers these days do not rely or even bother with window.open() unless it is for a specific purpose that is absolutely necessary. Note: there really isn't very many situations where window.open() is absolutely necessary.  I have no idea what you need this popup for so I can't really give you alternatives to it. 

 

But as far as the issue at hand...

 

2: Your window.location is redirecting before the popup has a chance to open.  There are 2 ways to go about this and you basically have to pick your poison.

 

You can timeout the redirect and give the popup a chance to execute.  This version should give the popup enough time to load (you can adjust the timeout by increasing 500 to something higher (it is in milliseconds)). Key behavior of this is that if your browser is set to ask to allow the popup, if you don't respond in time, the redirect will still happen, whether or not your popup actually occurred.  This may either be good or bad depending on your needs.

<script language="javascript"> window.open('SuccessMessage.php?fullview=Y','','height=300,width=525,resizable=yes,scrollbars=yes');</script>
<script> window.setTimeout("window.location='index.html';",500); </script>

 

Alternatively you can wrap the redirect in a condition, where window.open() is what is evaluated.  This will cause the redirect to only happen if the popup actually occurs, including waiting around to find out whether or not you accept the popup if your browser prompts you.  Again, this may or may not be ideal for you, depending on what the actual purpose of your popup is for.

<script language="javascript"> 
if (window.open('SuccessMessage.php?fullview=Y','','height=300,width=525,resizable=yes,scrollbars=yes'))
  window.location='index.html';
</script>

Link to comment
Share on other sites

 

As explained, with popup blocking enabled (the usual browser default), a popup must be user requested to open - the user must click on something, else it is blocked.  You can get a similar effect by putting the form and confirmation message in an iframe.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.