(2017-02-18, 06:37 PM)thelovelyone Wrote: [ -> ]I want to add a sound notification, is that possible? E.g. there is a new alert, itll give a sound when you open the forum.
I am not exactly sure about this plugin, because I just downloaded it and it doesn't even work for me.
anyway something like this should do the work. Keep the audio tags within the body, and before using the script make sure to check the number of alerts, then use if condition and enclose the " document.getElementById("alert_sound").play();", so if there are alerts more than 0 make it true like
if(alert_number > 0)
{
document.getElementById("alert_sound").play();
}
, then it will trig the sound to play.
Quote:<audio id="alert_sound" src="myalert.mp3"></audio>
<script>
document.getElementById("alert_sound").play();
</script>
Even though the plugin doesn't work as I showed above, still I can see the number of alerts in my site. Currently it shows as 0. So I made this javascript solution for playing notifications. This should work, but didn't test.
As I found the number of alerts show in "
myalerts" class.
<li class="alerts ">
<a href="https://nucuta.com/community/alerts.php" class="myalerts">Alerts(1)</a>
</li>
So.. Use this code to retrieve the number of alerts that it shows. As I believe, it shows the number of alerts received, but it shows with some characters. in that case regular expression has to be used to retrieve the number out of it.
<script>
var number = document.getElementsByClassName("myalerts")[0].innerHTML;
var num = number.match(/\d/g)[0];
</script>
Then use a if condition to find out if it's larger than 0..
<audio id="alert_sound" src="myalert.mp3"></audio>
<script>
if(num > 0){
document.getElementById("alert_sound").play();
}
</script>
The complete code should be this...
<audio id="alert_sound" src="myalert.mp3"></audio>
<script>
var number = document.getElementsByClassName("myalerts")[0].innerHTML;
var num = number.match(/\d/g)[0];
if(num > 0){
document.getElementById("alert_sound").play();
}
</script>