PDA

View Full Version : HTML display once


Manz16
04-24-2008, 12:15 PM
Is there a html script to display something only once?
i have a popup box appearing on a forum when you recieve a new private message, saying click on OK to view it or cancel, i added the code in my header so that it comes up on any page you go on, whenever you click on cancel it keeps comming up on any page you go on, but when you click on OK, it goes to your PM inbox.
Is there a way to make this message box appear only once? with html?

this is the code that i am using


<script language="javascript" type="text/javascript">
<!--
if( {PRIVATE_MESSAGE_NEW_COUNT} >0 )
{
new_pm_prompt = confirm('A new private message is waiting for you in your Inbox. Click OK to view it.');
if(new_pm_prompt == true) {
// Redirect to Inbox if OK is clicked
window.location = 'privmsg.php?folder=inbox';
}
else {
// Close prompt if cancel is clicked
}
}
//-->
</script>


any help would be appreciated.

thanks

Sagacious
04-24-2008, 01:47 PM
One way would be to use Javascript to set a cookie. That way the script would only display the popup if the cookie wasn't there. You would need an unset cookie script to run when a new private message is recieved though - or the user will not see a new popup when new private messages arrive in the future.

It might be a slightly long way around the problem - but if you don't mind the idea I can give you some scripts to use to make it work. HTML in itself is not clever enough to figure this out on its own, so this might get moved to the Javascript forum.

Manz16
04-24-2008, 05:03 PM
ok thanks, could you tell me the javascript i can use for this?

Manz16
04-25-2008, 08:41 PM
bump

just want to know if anyone else knows how to do this?

psychaosx
04-25-2008, 09:28 PM
This page has an excellent overview of how to set up cookies using javascript:
http://www.quirksmode.org/js/cookies.html

What I would recommend doing is using a function that reads the cookie in your if statement's conditions, then using a function to set the cookie inside the actual if statement.

To unset the cookie, you could use a very similar if statement. The main difference would be checking that PRIVATE_MESSAGE_NEW_COUNT = 0 instead of >0.