为什么IE7兼容后退按钮php无法检测为IE7?

发布于 2024-11-07 22:31:24 字数 1204 浏览 0 评论 0原文

我在 IE7 兼容模式和 HTML5 方面遇到奇怪的问题。

症状:直接进入我的主页,使用PHP可以检测到是IE7。点击表单提交按钮并单击返回按钮后,即使仍处于兼容模式,它也不再检测为 IE7。必须刷新或重新加载才能再次检测为 IE7。

我可以做些什么来使其更加稳健?请不要说使用 get_browser 和 browscap。我不想继续维护 browscap.ini。

在 html 头部:

<?php 
    /**
    *   IE 7 has trouble with jscrollpane, so disable for all IE except for 9 which works just fine.
    */ 
    $getBrowser = $_SERVER['HTTP_USER_AGENT']; 
    if( (!stristr($getBrowser,'MSIE')) || stristr($getBrowser,'MSIE 9')):
?>
<script src="jquery/jquery.mousewheel.js"></script>
<link  rel="stylesheet" href="styles/jquery.jscrollpane.css" />
<script src="jquery/jquery.jscrollpane.min.js"></script>
<script  src="jquery/js.js"></script>
<?php endif; ?>

更新:

$getBrowser = $_SERVER['HTTP_USER_AGENT']; 
        if( stristr($getBrowser,'MSIE') === false)

将 js.js 行重新定位为:

<!--[if IE 9 ]>
    <script  src="jquery/js.js"></script>
<![endif]-->

点击后退按钮时仍然执行相同的操作。

编辑:伙计......我想我遇到了一些严重的机器问题。那个带窗户的盒子一定是在窗户更新后被搞砸了。为这些疯狂的事情感到抱歉。在另一台尚未运行 Windows 更新的计算机上运行良好。

I am having weird issues with IE7 Compatibility mode and HTML5.

Symptoms: Going directly to my homepage, using PHP can detect that it is IE7. After hitting a form submit button, and clicking the return back button, it no longer detects as IE7 even while still in compatibility mode. Must be refresh or reloaded to detect as IE7 again.

What can I do to make this more robust? Please don't say to use get_browser and browscap. I do not wish to keep maintain on that browscap.ini.

in the html head:

<?php 
    /**
    *   IE 7 has trouble with jscrollpane, so disable for all IE except for 9 which works just fine.
    */ 
    $getBrowser = $_SERVER['HTTP_USER_AGENT']; 
    if( (!stristr($getBrowser,'MSIE')) || stristr($getBrowser,'MSIE 9')):
?>
<script src="jquery/jquery.mousewheel.js"></script>
<link  rel="stylesheet" href="styles/jquery.jscrollpane.css" />
<script src="jquery/jquery.jscrollpane.min.js"></script>
<script  src="jquery/js.js"></script>
<?php endif; ?>

Updated:

$getBrowser = $_SERVER['HTTP_USER_AGENT']; 
        if( stristr($getBrowser,'MSIE') === false)

Relocated js.js line to:

<!--[if IE 9 ]>
    <script  src="jquery/js.js"></script>
<![endif]-->

Still does the same thing when hitting back button.

Edit: Man.... I guess I am having some serious machine problems. The box with windows must have been screwed up after the windows update. Sorry for this crazy stuff. Works fine on another machine that has not ran windows update yet.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

時窥 2024-11-14 22:31:24

我没有 IE9,所以无法尝试,但你不能做这样的事情并将其放在 上:

<!--[if IE 9]>
     // your includes here
<![endif]-->

不确定仍然看到该内容对你是否重要script 标签包含在源代码中,但至少它不会执行它们,除非检查得到满足。

I don't have IE9 so I can't try it but can't you do something like this and place it on the <head>:

<!--[if IE 9]>
     // your includes here
<![endif]-->

Not sure if it matters to you to still see the script tags included in the source but at least it won't execute them unless the check was satisfied.

临风闻羌笛 2024-11-14 22:31:24

正如 @tradyblix 所说,您可以在客户端执行此操作。它们被称为条件注释

如果您必须在 PHP 中执行此操作,我会使用 strpos()。

$ua = $_SERVER['HTTP_USER_AGENT'];
if (stripos($ua, 'MSIE') === false || stripos($ua, 'MSIE 9') !== false)

As @tradyblix said, you can do this client side. They're called conditional comments.

If you have to do it in the PHP, I would use strpos().

$ua = $_SERVER['HTTP_USER_AGENT'];
if (stripos($ua, 'MSIE') === false || stripos($ua, 'MSIE 9') !== false)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文