为什么IE7兼容后退按钮php无法检测为IE7?
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有 IE9,所以无法尝试,但你不能做这样的事情并将其放在
上:
不确定仍然看到该内容对你是否重要
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>
: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.正如 @tradyblix 所说,您可以在客户端执行此操作。它们被称为条件注释。
如果您必须在 PHP 中执行此操作,我会使用 strpos()。
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().