Ben*_*Ben 3 html javascript css jquery alert
我在Javascript上很糟糕,但不幸的是,我需要完成这一项任务.我需要一个JavaScript警告,只显示一次-每个浏览器会话不是一次,而是一次过.我正在为一个学校竞赛做一个项目; 该警报将涉及Internet Explorer与我的网站不兼容的方式,建议使用Chrome或Firefox.但是,我不想用弹出窗口来判断评委,所以只出现一次才是最好的.我发现在线下面显示的代码,但我无法使其正常工作.它可能就像在某处缺少括号一样简单 - 再次,我不擅长Javascript,只是HTML和CSS.:P如果鼓励替代代码执行我的请求,那么无论如何,建议它!谢谢大家!
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<!--[if IE]>
<script type="text/javascript">
$(document).one(function() { alert("You are using Internet Explorer to view this webpage. Your experience may be subpar while using Internet Explorer; we recommend using an alternative internet browser, such as Chrome or Firefox, to view our website."); } );
</script>
<![endif]-->
Run Code Online (Sandbox Code Playgroud)
one 不是你需要的,因为页面刷新将覆盖所有'内存'.
您很可能正在寻找,localStorage或者,如果您使用的是第8版之前的Internet Explorer,请使用Cookie:
<script type="text/javascript">
var alerted = localStorage.getItem('alerted') || '';
if (alerted != 'yes') {
alert("You are using Internet Explorer to view this webpage. Your experience may be subpar while using Internet Explorer; we recommend using an alternative internet browser, such as Chrome or Firefox, to view our website.");
localStorage.setItem('alerted','yes');
}
</script>
Run Code Online (Sandbox Code Playgroud)
编辑:
对于8之前的IE版本,您需要使用cookie,因为没有支持localStorage.这是完全相同的概念,只是不同的方法.请查看此问题,以便在您的网页上实施Cookie.
从示例中复制代码后,您应该有2个函数 - createCookie()和getCookie().
var createCookie = function(name, value, days) {
....
//copy it from the other question
..
}
function getCookie(c_name) {
....
//copy it from the other question
..
}
<!--[if IE]>
<script type="text/javascript">
var alerted = getCookie('alerted') || '';
if (alerted != 'yes') {
alert("You are using Internet Explorer to view this webpage. Your experience may be subpar while using Internet Explorer; we recommend using an alternative internet browser, such as Chrome or Firefox, to view our website.");
createCookie('alerted','yes',365);//cookies expires after 365 days
}
</script>
<![endif]-->
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
12631 次 |
| 最近记录: |