我創建了一個引導模式彈出窗口,它完全顯示並消失。我需要做的是檢查是否存在cookie,並且只有當用戶在站點上時才彈出一次。我也有一個關閉按鈕。目前,每次刷新頁面時都會顯示,但我不確定如何使其正常工作。我看到一些谷歌搜索的例子,但沒有爲我工作。誰能幫忙?由於Bootstrap模態和cookie
這裏是我的javascript:
$(document).ready(function() {
if (document.cookie != "") {
$("#myModal").modal("show");
$("#myModalClose").click(function() {
$("#myModal").modal("hide");
});
}
});
這裏是我的HTML:
<div id="myModal" class="modal fade in">
<div class="inner-modal">
<div class="modal-container">
<p>some text</p>
<button class="close" data-dismiss="modal" data-target="#myModal">Hide this message</button>
</div>
</div>
</div>
不應該'如果(document.cookie中!= 「」)'是'如果(document.cookie中== 「」)'? – DavidG 2014-10-29 12:33:23
嗨@DavidG當我將它從!=更改爲==我的模態彈出式中斷。 – fnk 2014-10-29 12:37:44
以什麼方式打破?無論如何,編寫'if(!document.cookie)' – DavidG 2014-10-29 12:38:39