0
I have a code, I wish to make a notification system in live push, here is my code:
<script>
Notification.requestPermission();
function requisitar(){
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
var text=xmlhttp.responseText;
if (xmlhttp.readyState==4 && xmlhttp.status==20)
{
var notification = new Notification("Site DaviDEV", {
icon: 'http://i.imgur.com/cWk851f.png',
body: text
});
notification.onclick = function() {
window.open("<?php echo $url; ?>");
}
}
}
xmlhttp.open("GET","/notificacao/notificacao.txt",true);
xmlhttp.send();
}
window.setInterval(requisitar, 1000);
</script>
The more he can read the file and send the notification, the more he has a problem: He keeps sending several notifications, like spam, I want something that only sends one to each person, what can I do?
The reason for "spam" is
window.setInterval
, try to remove or use awindow.setTimeout
... I just didn’t understand why useif (window.XMLHttpRequest)
when the Browser is recent enough to make the Notification API available.– Tobias Mesquita
The more I want live, for exeplo I edited the text there, everyone sees. then it goes away, if I edit again it goes and announces the new.
– DaviDEV
Can you explain the question better? what do you mean "I edited the text there"? ( and by the way, I think you want to have 200 here
xmlhttp.status==20)
)– Sergio