Jump to content

[SOLVED] Javascript problem (need to stop the box poping up)


joel2k8

Recommended Posts

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!

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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)

Link to comment
Share on other sites

<?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

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.