在perl中检测浏览器,如何检查浏览器是否是perl中的Internet Explorer(IE)

时间:2011-11-25 13:45:36

标签: javascript perl

$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不会改变。

1 个答案:

答案 0 :(得分:6)

此代码无效。

我假设您的Perl代码在网络服务器上运行,但您的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!');  
}