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:
- set the hide option in a table in your database, i.e. userPreference to true
- redirect the user back to the page that he is viewing.
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:
- I utilised jQuery's hide. Read on it.
- You can read more about jQuery cookie plugin here.