使用 Twitter Bootstrap,你如何“记住"?用户操作? [英] Using Twitter Bootstrap, how can you "remember" user actions?
问题描述
我正在使用 Bootstrap Alerts 框,并且希望这些框能够记住"它们是否已关闭.这样当用户登录会员区并关闭警报时;下次他们访问该网站时,警报仍然消失.
有没有办法做到这一点?
我正在使用 Bootstrap Alerts 框,并且希望这些框能够记住"它们是否已关闭.这样当用户登录会员区并关闭警报时;下次他们访问该网站时,警报仍然消失.
有没有办法做到这一点?
如果您使用服务器选项,则必须将 hideMe.php 编码为:
免责声明:这些代码旨在让您了解如何完成.但是,无法保证它会按原样工作,因为我没有测试代码.
注意事项:
I am using the Bootstrap Alerts boxes, and would like these boxes to "remember" if they have been closed. This way when a user logs in to the members area and closes an alert; the next time they visit the site the alert is still gone.
Is there any way to do this?
<div class="alert-message success" data-alert="alert">
<a class="close" data-dismiss="alert" href="#">×</a>When I click × I'd like this to never appear again.</div>
You probably will have to store that preference in the cookies or on the server itself. A good read can be found in another SO thread.
For storing cookies Basically, what you have to do is to implement javascript around your codes. For simplicity, I utilise jQuery and a jQuery cookie plugin.
// jQuery pulled from Google CDN
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
// jQuery cookie plugin. You will have to download it on your own: https://github.com/carhartl/jquery-cookie
<script src="/path/to/jquery.cookie.js"></script>
// jQuery action here
<script>
function runOnLoad(){
if($.cookie('alert-box') == null) {
$.cookie('alert-box', 'open', { expires: 7 });
} else if($.cookie('alert-box') == 'close') {
$(".close").hide();
}
// php psuedo code here (if you are using the server option)
<?php
if(check database for hide option == true){
echo '$(".close").hide();
}
?>
}
function hideMe(){
$.cookie('alert-box', 'close', {expires:7 });
$(".close").hide();
}
</script>
<body onload="runOnLoad()">
<div class="alert-message success" data-alert="alert">
<a class="close" data-dismiss="alert" href="hideMe.php" onclick="hideMe()" >×</a>When I click × I'd like this to never appear again.
</div>
</body>
If you are using the server option, you have to code hideMe.php to:
Disclaimer: These codes are to give you an idea how it can be done. However, there is no gaurantee that it will work as it is, as I did not test the code.
Notes:
这篇关于使用 Twitter Bootstrap,你如何“记住"?用户操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!