I made a script which is used for checking unread notification. And it must be worked across all screen so it has been written in header of my project and it works well. Since it has been written in header,here i want to avoid it if i open more than one tab which means this process should be checked at one tab only even though more than one tab opens at a time.
window.onload=function(){
fnCheckOrdStaNoti();
setInterval(fnCheckOrdStaNoti, 15000);
}
function fnCheckOrdStaNoti(){
$.ajax({
url: 'notification.php',
type: 'post',
dataType: 'html',
crossDomain: true,
success: function(hdata) {
// hdata has some information regarding notification
// based on result i trigger another ajax function.
// here i have to check how many no of browser tab has been opened with respect to my project. and have to be triggered another ajax function to the first tab only, rest should be restricted.
},
error: function(xhr, ajaxOptions, thrownError) {
console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
}