How To Stop Javascript Alert From Showing After Pressing Ok
I want to show an alert if I have something in my Facebook inbox. I think it can be easily accomplished using userscripts... this is what I have so far (thanks to the guys at the u
Solution 1:
Add a variable which keeps track of how many messages there were last alert, and do not show if that variable hasn't changed.
Something like:
document.addEventListener(
"DOMNodeInserted",
function() {
var count = parseInt(document.getElementById("fb_menu_inbox_unread_count").textContent);
if (count > 0 && count != lastCount) {
alert("You have "+count+" new message"+(count==1 ? "" : "s")+"."); }, true);
}
lastCount = count; // Remember count to avoid continuous alerts.
Also, I would avoid writing code all in one like, as you did in your original post. It makes it more difficult to read and change if need be.
Solution 2:
Set a custom cookie using document.cookie to save the count, then do your regular checks
Post a Comment for "How To Stop Javascript Alert From Showing After Pressing Ok"