Gop*_*ath 12 asp.net internet-explorer internet-explorer-6
就像其他所有的Web开发人员一样,我很沮丧我的网站代码与IE 6一起工作.所以决定放弃对IE 6的支持并礼貌地要求他们升级到IE 7+或Firefox.
您能否建议我如何检测IE6用户并显示一个显示ASP.NET MVC升级细节的特殊页面?
在服务器端处理这个脚本是个好主意吗?或者你建议使用像jQuery这样的客户端脚本来处理这个问题吗?
Ste*_*ter 20
最简单的事情IMO是创建一个动作过滤器属性.然后你可以用它标记你的控制器(或添加到MVC3中的全局过滤器).
这是属性:
/// <summary>
/// If the user has IE6, this will present them with a page that tells them they have a crappy old browser. It gives them options to upgrade but they can also
/// choose to proceed anyway. This check is done only when they first visit the site. A cookie also prevents unnecessary future checks, so this won't slow the app down.
/// </summary>
public class WarnAboutIE6Attribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var request = filterContext.HttpContext.Request;
//this will be true when it's their first visit to the site (will happen again if they clear cookies)
if (request.UrlReferrer == null && request.Cookies["browserChecked"] == null)
{
//give old IE users a warning the first time
if (request.Browser.Browser.Trim().ToUpperInvariant().EqualsExact("IE") && request.Browser.MajorVersion <= 6)
{
filterContext.Controller.ViewData["RequestedUrl"] = request.Url.ToString();
filterContext.Result = new ViewResult { ViewName = "InternetExplorerOldWarning" };
}
filterContext.HttpContext.Response.AppendCookie(new HttpCookie("browserChecked", "true"));
}
}
}
Run Code Online (Sandbox Code Playgroud)
此属性检查IE6,如果它存在,则呈现您必须创建的"InternetExplorerOldWarning"视图.它只使用cookie呈现此警告一次.你当然可以调整你想要的.在我看来,我给了他们更新或下载其他浏览器的链接.我也让他们有机会继续使用IE6.看看这个:
<h3>
Your Internet Explorer is Outdated</h3>
<div class="warning">Your version of Internet Explorer is a bit too old and unfortunately won't work well with this site.</div>
<p>Have no fear. You have options and in just a few minutes you can be rocking out in our app:</p>
<ul>
<li>If you have FireFox, Safari, or Google Chrome already on your computer use one of them for Takeoff instead.</li>
<li>Upgrade to the <a href="http://www.microsoft.com/windows/internet-explorer/worldwide-sites.aspx">latest Internet Explorer.</a> You can download and install right away. Even Microsoft recommends you do this.</li>
<li>Download an Internet Explorer alternative. We recommend <a href="http://www.mozilla.com/en-US/firefox/firefox.html">FireFox</a>, <a href="http://www.apple.com/safari/download/">Safari</a>, or <a href="http://www.google.com/chrome">Google Chrome</a>. Choose one or all because each is great!</li>
</ul>
<p>This warning page will only show once. If you really want to use Takeoff with your current Internet Explorer, we won't stop you. But beware, it will probably look like garbage!</p>
<p>Whatever dude, I want to <a href="@ViewData["RequestedUrl"] ">my old, insecure, scary, dangerous version</a> of Internet Explorer.</p>
</div>
Run Code Online (Sandbox Code Playgroud)
exi*_*ang 13
您可以从编码中进行检测:
// ASP.net MVC C# example
if (Request.Browser.Browser == "IE" && Request.Browser.Version.ConvertTo<float>() < 7.0)
{
// output message to urge user to upgrade to latest IE browser
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9284 次 |
| 最近记录: |