Click to See Complete Forum and Search --> : Popup box
fatepower
09-18-2008, 06:46 PM
Hi
Now i have on my site a Javascript confirmbox who are allways showing when they recive a new PM:
<script type="text/javascript">
function newpm() {
<!--
var answer = confirm ("You have a new PM, please click OK to go to your PM Inbox.")
if (answer)
window.location='usercp.php?uid=<? echo $CURUSER["uid"]; ?>&do=pm&action=list'
// -->
}
</script>
$resmail=mysql_query("SELECT COUNT(*) FROM messages WHERE readed='no' AND receiver=$CURUSER[uid] AND delbyreceiver='no'");
if ($resmail && mysql_num_rows($resmail)>0)
{
$mail=mysql_fetch_row($resmail);
if ($mail[0]>0) {
if (substr($_SERVER['PHP_SELF'], -10)!="usercp.php")
print( "<script language=\"javascript\">newpm();</script>");
print("<td class=lista align=center><a href=usercp.php?uid=".$CURUSER["uid"]."&do=pm&action=list>".MAILBOX."</a> (<font color=\"#FF0000\"><b>$mail[0]</b></font>)</td>\n");
} else
print("<td class=lista align=center><a href=usercp.php?uid=".$CURUSER["uid"]."&do=pm&action=list>".MAILBOX."</a></td>\n");
}
else
print("<td class=lista align=center><a href=usercp.php?uid=".$CURUSER["uid"]."&do=pm&action=list>".MAILBOX."</a></td>\n");
Well this is little annoying because they see that bloody box everytime, even if the click cancel when they have recived a new PM.
Well i thinked if there would be possible to add a box maybe ajax or php with an option to tick dont show this again on this browser session. A window like this:
http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/index.htm
as an example or just a Confirm box but it will only show once at the browser session/ or every 10 min, when they click cancel.
Whould be nice with some help :)
Cheers
bpat1434
09-18-2008, 08:36 PM
Well, you could add to your javascript that if(!answer) then set a timeout for 10 minutes. You might want to add something to the session and/or cookie so they're not annoyed by the box.
fatepower
09-19-2008, 10:58 AM
Yes that sounds good but how mate :D
bpat1434
09-19-2008, 11:11 AM
Well, there's always the Javascript method setTimeout (google it) or you can google on editing cookies/sessions via JavaScript.
I'm not master at JS so I'm not sure.
fatepower
09-19-2008, 11:14 AM
Well, i must say i tried that all evening yesterday with now good resualts. Java ain't my best side. :-/
bpat1434
09-19-2008, 11:22 AM
Writing cookies in javascript (http://www.google.com/search?hl=en&q=writing+cookies+in+javascript&btnG=Google+Search&aq=1&oq=writing+cookies+) (3,350,000)
JavaScript - Cookies (http://www.google.com/url?sa=t&source=web&ct=res&cd=1&url=http%3A%2F%2Fwww.quirksmode.org%2Fjs%2Fcookies.html&ei=HLTTSNH5H530ebK9-KcK&usg=AFQjCNEg2QE9VMGZnxWstMKBZjFY8Z_-Ng&sig2=bXmShq2yZkwrIzScjXl1Gg)
Writing Cookies (http://www.google.com/url?sa=t&source=web&ct=res&cd=2&url=http%3A%2F%2Fjavascript.about.com%2Flibrary%2Fblwcookie.htm&ei=HLTTSNH5H530ebK9-KcK&usg=AFQjCNHzGnJIXACXDaaDMIfkQ0UEknmF4g&sig2=jnKy8fZLdoppOok_vPHORw)
Cookies | set and retrieve information about your users (http://www.google.com/url?sa=t&source=web&ct=res&cd=7&url=http%3A%2F%2Fwww.yourhtmlsource.com%2Fjavascript%2Fcookies.html&ei=HLTTSNH5H530ebK9-KcK&usg=AFQjCNFuWHq2GKZK4Nkp9mdxeBjk_6ZaAw&sig2=HsUQcJzJ3J7vbPtbz1oo9w)
settimeout javascript function (http://www.google.com/search?hl=en&q=settimeout+javascript+function&btnG=Google+Search&aq=2&oq=settimeout+javascript) (977,000)
JavaScript Timing Events (http://www.google.com/url?sa=t&source=web&ct=res&cd=2&url=http%3A%2F%2Fwww.w3schools.com%2Fjs%2Fjs_timing.asp&ei=JLXTSPiWIJjEeuqYrJwK&usg=AFQjCNFkWK5XLaslzcd5uM3rUtr3fyjP0Q&sig2=a25UeiNzdwMa4l-oeRbstw)
JavaScript Tutorial - using setInterval and setTimeout (http://www.google.com/url?sa=t&source=web&ct=res&cd=9&url=http%3A%2F%2Fblog.paranoidferret.com%2Findex.php%2F2007%2F09%2F06%2Fjavascript-tutorial-using-setinterval-and-settimeout%2F&ei=JLXTSPiWIJjEeuqYrJwK&usg=AFQjCNG42LpAg_5Y-uE9hGkmEvh0Bh_c5A&sig2=su45r3TRX60zz4fb9BO7TQ)
setTimeout or setInterval (http://www.google.com/url?sa=t&source=web&ct=res&cd=4&url=http%3A%2F%2Fjavascript.about.com%2Flibrary%2Fblstvsi.htm&ei=JLXTSPiWIJjEeuqYrJwK&usg=AFQjCNGzyKHE_l2EtWl3MT9vzGBpMHtQGA&sig2=QP_XOV3mca60eHFYLp4M-g)
Those are just a few, but should get you started....
fatepower
09-19-2008, 11:37 AM
So you do not have a code example of just sett a timeout for 10 mins? I mean, yes google is nice but so i can get it to work with the confirm box.
bpat1434
09-19-2008, 11:48 AM
1 second = 1000 milliseconds;
1 minute = 60 seconds;
10 minutes = 600 seconds;
10 minutes in milliseconds = 600*1000 = 600000;
So to set the timeout for 10 minutes, you'd have to use:
setTimeout('popupBox()', 600000);
fatepower
10-08-2008, 07:42 AM
so i need to do a else tag then and then insert the timeout?
bpat1434
10-08-2008, 08:30 AM
sure.... try and find out ;)
fatepower
10-08-2008, 09:09 PM
Sorry but somthing like this mate :D
<script type="text/javascript">
function newpm() {
<!--
var answer = confirm ("You have a new PM, please click OK to go to your PM Inbox.")
if (answer)
window.location='usercp.php?uid=<? echo $CURUSER["uid"]; ?>&do=pm&action=list'
else
setTimeout('popupBox()', 600000);
// -->
}
</script>
or:
<script type="text/javascript">
function newpm() {
<!--
var answer = confirm ("You have a new PM, please click OK to go to your PM Inbox.")
if (answer)
window.location='usercp.php?uid=<? echo $CURUSER["uid"]; ?>&do=pm&action=list'
else if (!answer)
setTimeout('popupBox()', 600000);
// -->
}
</script>
Cheerz
bpat1434
10-08-2008, 09:16 PM
The first should be fine... however make sure the function you're calling is in fact defined ....
fatepower
10-08-2008, 09:41 PM
What do you mean with defined?
Weedpacket
10-08-2008, 09:51 PM
If there's no such function as "popupBox" then calling popupBox() won't work.
fatepower
10-08-2008, 09:59 PM
Ok i c.
See the first post here in this topic, i define the js function in the start of the file. Then call it later if the users has recived a new PM.
bpat1434
10-08-2008, 10:36 PM
No, I see a function called "newpm" not "popupbox". So your timer is useless unless you call the correct function which would seem to be "newpm", not "popupbox".
Alag15
10-11-2008, 04:23 AM
where is my post ?
bpat1434
10-11-2008, 11:16 AM
Not within this thread...
fatepower
10-11-2008, 07:45 PM
But that function will give me a "confirm"box with ok and cancel?
I dont really get what i mean if i shall be honest, sorry.
Cheers
bpat1434
10-11-2008, 08:27 PM
Okay, let me break this down for you...
You came here asking for help and posted code of which there is only one function named "newpm". Then we helped you, and your code showed that you would be calling a function called "popupBox" after a specific time. We didn't see such a function, so we told you to make sure it's actually defined (as in you have "function popupBox() { }" somewhere in your code).
So if you want to pop-up a box saying "You have X unread messages, read now?" with an "OK" and "Cancel" button, then just call "newpm" again, not "popupBox". Otherwise, define your function popupBox.
I don't know how else to explain it.....
Either use:
function newpm() {
var answer = confirm ("You have a new PM, please click OK to go to your PM Inbox.")
if (answer)
window.location='usercp.php?uid=<? echo $CURUSER["uid"]; ?>&do=pm&action=list'
else
setTimeout('popupBox()', 600000);
}
function popupBox() {
alert('You have some unread messages!');
}
Or:
function newpm() {
var answer = confirm ("You have a new PM, please click OK to go to your PM Inbox.")
if (answer)
window.location='usercp.php?uid=<? echo $CURUSER["uid"]; ?>&do=pm&action=list'
else
setTimeout('newpm()', 600000);
}
fatepower
10-13-2008, 08:21 AM
Thanks you, now we have made it cleary. But this will not work because everytime a users repload the page the function new(); will run again. So even if they click cancel they will see the opoup box again after they click cancel :-/
PHP Builder
Copyright Internet.com Inc. All Rights Reserved.