检测 IE 浏览器并仅发出一次警报
我刚刚从各个站点获取了这段代码,并用我自己的代码来完成以下任务。
我想检测 IE 浏览器,并希望在整个会话期间仅提醒成员一次。我该怎么做?以下是我正在使用的代码。
<SCRIPT language="JavaScript">
<!--
var once_per_session=1
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function alertornot(){
if (get_cookie('alerted')==''){
loadalert(alert)
document.cookie="alerted=yes"
}
}
function loadalert(){
var browserName=navigator.appName;
if (browserName=="Microsoft Internet Explorer")
{
alert("Our Web Panel best viewed in Google Chrome and Firefox 3+ You may still continue but some features may not work properly..");
}
}
if (once_per_session==0)
loadalert()
else
alertornot()
//-->
</SCRIPT>
这真的可以通过检测浏览器来报警一次吗?请帮忙。
I just grabbed this code from various sites and came out with my own to accomplish the following.
I want to detect an IE Browser and would like to alert the members ONLY Once through out their session. How Do I Do this? Following is the code, which I'm using.
<SCRIPT language="JavaScript">
<!--
var once_per_session=1
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function alertornot(){
if (get_cookie('alerted')==''){
loadalert(alert)
document.cookie="alerted=yes"
}
}
function loadalert(){
var browserName=navigator.appName;
if (browserName=="Microsoft Internet Explorer")
{
alert("Our Web Panel best viewed in Google Chrome and Firefox 3+ You may still continue but some features may not work properly..");
}
}
if (once_per_session==0)
loadalert()
else
alertornot()
//-->
</SCRIPT>
Is this really possible to alert once by detecting the browser? Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用IE的条件注释。浏览器的 userAgent 不可靠。
或者,您可以使用此技巧
我更喜欢
Conditional comments
解决方案,您可以选择其中之一You can use Conditional comments of IE. Browser's userAgent is not reliable.
Or, you can use this trick
I prefer the
Conditional comments
solution, you can choose either one