介绍如何在perl中检查浏览器是否为IE

detect browser in perl,how to check if the browser is internet explorer(IE) in perl

本文关键字:浏览器 检查 是否 IE perl      更新时间:2023-09-26
$msg_box_ok_id=smthin;
print<<HTML_alert;
<script type="text/javascript" language="JavaScript">
    if (browserName=="Microsoft Internet Explorer"){
        $msg_box_ok_id=somthinnew;      
    }
</script>
HTML_alert
;

我正在使用这段代码,但javascript无法识别变量。

所以变量$msg_box_ok_id不会改变

这段代码不能运行

我假设你的Perl代码运行在web服务器上,但是你的JavaScript运行在客户端- pc上。

所以JavaScript代码不能以这种方式影响服务器端的程序逻辑。

看一下HTTP::BrowserDetect模块的例子。

顺便说一下,JavaScript中的浏览器检测不会以这种方式工作:http://www.w3schools.com/jsref/prop_nav_useragent.asp
/* check the agent */  
 function checkBrowserName(name){  
   var agent = navigator.userAgent.toLowerCase();  
   if (agent.indexOf(name.toLowerCase())>-1) {  
     return true;  
   }  
   return false;  
 }  

if(checkBrowserName('MSIE')){  
  alert('Internet Explorer!');  
}