admin管理员组文章数量:1293512
I have a bootstrap alert.
<div class="checkbox">
<label>
<input type="checkbox"> Don't show this again!
</label>
</div>
If the checkbox is clicked and alert is dissmissed
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
I don't want to show the alert ever again. I am wondering if this can be done with .asp
$('#checkbox').click(function() {
if ($('#checkbox').attr('checked')) {
document.cookie="alert=dismiss";
}
})
and then if there is a cookie hide the message $.hide
method?
Updated with Solution
var oldBrowser = $.browser.msie && parseInt($.browser.versionNumber) < 9;
//message is dismissed via storage
var dissmissed = amplify.store("DoNotShowMessageAgain");
// if oldbrowers and not dismissed
if (oldBrowser && !dissmissed) {
$( "#browserAlert" ).show();
}
// Don't show message again
$('#browserAlert .close').click(function(){
if ($('.checkbox input').is(':checked')) {
amplify.store( "DoNotShowMessageAgain", true );
}
})
I have a bootstrap alert.
<div class="checkbox">
<label>
<input type="checkbox"> Don't show this again!
</label>
</div>
If the checkbox is clicked and alert is dissmissed
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
I don't want to show the alert ever again. I am wondering if this can be done with http://www.w3schools./js/js_cookies.asp
$('#checkbox').click(function() {
if ($('#checkbox').attr('checked')) {
document.cookie="alert=dismiss";
}
})
and then if there is a cookie hide the message $.hide
method?
Updated with Solution
var oldBrowser = $.browser.msie && parseInt($.browser.versionNumber) < 9;
//message is dismissed via storage
var dissmissed = amplify.store("DoNotShowMessageAgain");
// if oldbrowers and not dismissed
if (oldBrowser && !dissmissed) {
$( "#browserAlert" ).show();
}
// Don't show message again
$('#browserAlert .close').click(function(){
if ($('.checkbox input').is(':checked')) {
amplify.store( "DoNotShowMessageAgain", true );
}
})
Share
Improve this question
edited Sep 13, 2017 at 1:29
nolawi
asked Aug 5, 2015 at 20:56
nolawinolawi
4,6496 gold badges25 silver badges46 bronze badges
1
- Yes - you can do it with cookies. You might want to spend a little more time on the cookie assignment code to ensure existing cookies are not overwritten. – user2182349 Commented Aug 5, 2015 at 20:59
1 Answer
Reset to default 8My remendation would be to use HTML5's local storage for this. Its very purpose is a modern way to persist data between sessions for a browser with no expiration:
function localStorageAvailable() {
if (typeof(Storage) !== "undefined") {
return true;
}
else {
return false;
}
}
$('#checkbox').click(function(){
if ($('#checkbox').attr('checked')) {
if (localStorageAvailable())
localStorage.DoNotShowMessageAgain = "true";
}
})
And then then, when the page is ready, you would want to check and restore the functionality from a past saved experience:
if (localStorageAvailable()) {
if (localStorage.DoNotShowMessageAgain && localStorage.DoNotShowMessageAgain === "true") {
// user doesn't want to see the message again, so handle accordingly
}
};
For more information on HTML5's local storage, take a look at my blog post on the topic.
本文标签: javascriptHow do I add a 39don39t show this message again39 checkbox with localstorageStack Overflow
版权声明:本文标题:javascript - How do I add a 'don't show this message again' checkbox with localstorage? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741580483a2386543.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论