我遇到了这个特定于PHP浏览器的警报的问题

时间:2012-01-20 03:24:28

标签: php javascript

我目前正在为开发人员编写一个设计教程网站,如果最终用户在屏幕上使用过时版本的IE,我会有一小段代码基本上会在页面上抛出一个小警报。

听起来毫无用处,这是客户想要的。那好吧。

基本上,当你点击“关闭此框”链接时,我无法理解该关闭。这是代码。有什么建议?

<?php

// IE6,7,8 string from user_agent
$ie6 = "MSIE 6.0";
$ie7 = "MSIE 7.0";
$ie8 = "MSIE 8.0";

// detect browser
$browser = $_SERVER['HTTP_USER_AGENT'];

// yank the version from the string
$browser = substr("$browser", 25, 8);

// html for error
$error = "<div class=\"error\" id=\"error\"><strong>Alert:</strong> It appears that you    
are using Internet Explorer 6, 7, or 8.  While you may still visit this website we 
encourage you to upgrade your web browser so you can enjoy all the rich features this 
website offers as well as other websites. Follow this link to <a 
href=\"http://www.microsoft.com/windows/downloads/ie/getitnow.mspx\"><strong>Upgrade 
your Internet Explorer</strong></a><br /><div class=\"kickRight\"><a href=\"javascript: 
killIt('error');\"> Close This Box</a></div></div>";

// if IE6 set the $alert 
if($browser == $ie6){ $alert = TRUE; }
if($browser == $ie7){ $alert = TRUE; }
if($browser == $ie8){ $alert = TRUE; }

?>

然后你可以将它添加到身体中,无论你想要它:

<!-- IE6 Detect Advise Notice -->
<?php if($alert){ echo $error; } ?>
<!-- // end IE6 Detect Advise Notice -->

我不能把这该死的关闭。我不知道问题是什么。可能是javascript试图关闭PHP错误框。我不知道基于c语言,所以我不知道。任何帮助表示赞赏

2 个答案:

答案 0 :(得分:1)

您的关闭按钮正在尝试使用参数killIt()触发名为'error'的JavaScript函数。我猜你没有在页面上包含该功能,或者它有错误。

答案 1 :(得分:0)

只需将killIt javascript函数添加到HTML即可。它不会删除服务器端的任何PHP代码,而是删除浏览器中PHP代码的HTML输出。你还没有向我们展示killIt的代码,但我的猜测是它隐藏或删除了PHP打印的DIV。