joel2k8 Posted July 18, 2008 Share Posted July 18, 2008 Well I need some help, I have a little JavaScript in my header file, Like if someone gets a mail it will pop up the box and if they do not click on "Mailbox" on the side menu they will keep getting the pop up message on every page they click on, what i want to do is when they get a message the pop up message only comes up once and they can click on any page without getting a pop up message and without clicking on mail, I just want to alert my users that they have a Mail, here is the script i use so far: if ($ir['new_mail'] > 0) { echo '<script> alert("You have 1 new mail!") </script>'; } I want to stop the pop up box keep coming up, I would only want it to come up once, Please Help, Thanks! Quote Link to comment Share on other sites More sharing options...
Skittalz Posted July 18, 2008 Share Posted July 18, 2008 include this in the header <script type="text/javascript"> function disp_alert() { alert("You have 1 new mail"); } </script> And then this would be needed for your <body> tag <?php if ($ir['new_mail'] > 0) { echo '<body onLoad="disp_alert();">'; // you can add anything else you want to the body tag } Quote Link to comment Share on other sites More sharing options...
joel2k8 Posted July 18, 2008 Author Share Posted July 18, 2008 OK, I will try it now, thanks Quote Link to comment Share on other sites More sharing options...
joel2k8 Posted July 18, 2008 Author Share Posted July 18, 2008 well i just tried it and the pop up still keeps showing when i click on any link, etc if i click on a link the pop up will pop up and when i click "OK" and i go to click on another link the pop up will come up again, but if they read there mail the pop up will not pop up, what i want is when they have a mail the pop up box only shows once Quote Link to comment Share on other sites More sharing options...
Skittalz Posted July 18, 2008 Share Posted July 18, 2008 if ($ir['new_mail'] > 0) { echo '<body onLoad="disp_alert();">'; // you can add anything else you want to the body tag } else { echo '<body>'; } this should only be on the page they read their email Quote Link to comment Share on other sites More sharing options...
joel2k8 Posted July 18, 2008 Author Share Posted July 18, 2008 Its not working for some reason, it just keeps popping up on every link i click, Well I think ill find away around it adventurely, Thanks anyway! Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 18, 2008 Share Posted July 18, 2008 just put it on the main index page.. or main included page.. problem solved if the script is only on one of the pages then it will only pop up on that page.. if you included also in your script an extra variable.. like say x=0 then increment x once the pop up as popped once.. then say if(x=1) { don't pop up } else { POP UP! } Quote Link to comment Share on other sites More sharing options...
joel2k8 Posted July 18, 2008 Author Share Posted July 18, 2008 well let me just explain it a bit more, my website is a RPG text based game and there is a file called header.php which is controlling all the images and all the pages, like on my mailbox.php it would say at the top: include "header.php"; now if there is a user wondering around the site i would want a pop up message on any page saying "they have 1 new mail" because another user sent them a mail, but it just keeps showing the message not unless the user sees the message that they sent, which is i only want the message to appear once, even if they havnt read there mail, I just want the message to appear once not on every page they click on, hope you understand what i mean. Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 18, 2008 Share Posted July 18, 2008 right so.. use the variable and incrment it once the pop has been fired once.. thus tell it not tofire anymore example x=0; if(x==1) { DON"T FIRE THE POPUP } else { FIRE THE POP UP x++; } //now x=1 and will not fire the pop again see Quote Link to comment Share on other sites More sharing options...
joel2k8 Posted July 18, 2008 Author Share Posted July 18, 2008 right so.. use the variable and incrment it once the pop has been fired once.. thus tell it not tofire anymore example x=0; if(x==1) { DON"T FIRE THE POPUP } else { FIRE THE POP UP x++; } //now x=1 and will not fire the pop again see So how would i put that in my code, I just tried to understand what you mean, but I'm getting no where, if you could re-arrange the first code i posted then that will be a big thanks, sorry if I'm annoying. Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 18, 2008 Share Posted July 18, 2008 <?php $x=0; if($x==1) { echo(''); } else { if ($ir['new_mail'] > 0) { echo (" <script> alert('You have 1 new mail!'); </script> "); $x++; } } ?> there ya go man ps(I wish when I modified my post that it didn't royal (*@&^#$*(&@^#($ UP my dang code spacing) Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 18, 2008 Share Posted July 18, 2008 <?php $x=0; if($x==1) { echo(''); } else { if ($ir['new_mail'] > 0) { echo (" <script> alert('You have 1 new mail!'); </script> "); $x++; } } ?> there ya go man ps(I wish when I modified my post that it didn't royal (*@&^#$*(&@^#($ UP my dang code spacing) @forum modify post function : take that double post biznatch!!! hahaha Quote Link to comment Share on other sites More sharing options...
joel2k8 Posted July 18, 2008 Author Share Posted July 18, 2008 Thank You Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 18, 2008 Share Posted July 18, 2008 you are welcome if i have solved your problem please click topic solved button Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.