我有一個JS在任何新通知到達時播放通知聲音。它的工作原理完全正常,當一個新通知到來時,它應該播放聲音,它確實發揮。.html()在頁面更改或刷新時不起作用
notification
我在說的只是一個integer
,它是通過ajax調用從查詢返回的。我通過腳本將此integer
設置爲我的<asp:label.../>
。
的問題是:我已經寫上MasterPage
腳本。因此,每當我打開新頁面或刷新同一個頁面時,<asp:Label.../>
被清除,我通過腳本使用.html(value)
來設置,導致腳本在每次頁面刷新或其他頁面加載時再次運行聲音。
問題可能是,該值不是持續?
我希望值應該被設置爲標籤的html,並且其值也應該在所有頁面上保留。我應該怎麼做這個persistence
?
我的腳本是:通過類選擇
<script type="text/javascript">
myFunction();
function myFunction() {
$.get("AjaxServicesNoty.aspx", function (data) {
var recievedCount = parseInt(data);
alert(recievedCount);
var existingCount = $(".lblEventCount").text();
if (existingCount == "") {
existingCount = 0;
alert(existingCount);
}
else {
existingCount = parseInt($(".lblEventCount").text());
alert(existingCount);
}
// if (existingCount == "" && recievedCount != 0) {
// $(".lblEventCount").html(recievedCount);
// $(".lblAcceptedCount").html(recievedCount);
// var sound = new Audio("Sound/notificationSound.wav");
// sound.play();
// }
if ((parseInt(recievedCount) > parseInt(existingCount)) && existingCount == 0) {
$(".lblEventCount").html(recievedCount);
$(".lblAcceptedCount").html(recievedCount);
var sound = new Audio("Sound/notificationSound.wav");
sound.play();
}
else {
$(".lblEventCount").html(existingCount);
$(".lblAcceptedCount").html(existingCount);
}
});
}
setInterval(myFunction, 5000);
</script>
我不明白,很好,但在客戶端,如果你刷新asp.net頁面或從服務器重新加載頁面,這些值將不會持久。你嘗試過使用cookie嗎? – Serendipity
再次我不能訪問來自JS的會話和cookie值?我可以嗎 ? –
我剛剛看過,我可以從JS訪問cookies!無論如何,我會找到解決辦法!謝謝! –