这些 WebKit ASP 之间的差异:菜单修复
我知道有大量关于 ASP:Menu 与 WebKit 问题的帖子,但我找不到能回答我的问题的帖子。
我经常看到人们推荐两种不同的方法来解决 Apple WebKit 浏览器(即 Chrome、Safari)中的 ASP:Menu 问题。但实际上哪个更好呢?除了目标用户代理之外,这两个操作之间还有什么区别?我发现的唯一区别是第二个也适用于 Page_Load
事件。我认为其中一个客观上优于另一个,但我不知道它们之间的区别。它们各自是如何工作的?
两者都进入基页的 Page_PreInit()
方法。
1.清除浏览器适配器。
if (Request.UserAgent.Contains("AppleWebKit"))
{
Request.Browser.Adapters.Clear();
}
2.改变客户目标。
if (Request.UserAgent.Contains("Safari"))
{
Page.ClientTarget = "uplevel";
}
Google Chrome 的默认用户代理如下。它同时包含 Safari 和 WebKit,因此我怀疑目标用户代理是否存在显着差异。
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.X.Y.Z Safari/525.13.
I know there are a ton of posts on the ASP:Menu vs. WebKit issue in general, but I cannot find one that answers my question.
I frequently see people recommending two different methods to fix the problem with ASP:Menu
s in Apple WebKit browsers (i.e., Chrome, Safari). But which is actually better? What is the difference between these two actions besides the targeted user agent? The only difference I found is that the second will also work on the Page_Load
event. I assume one is objectively superior to the other, but I do not know the difference between them. How do each of them work?
Both go in the Page_PreInit()
method of the base page.
1. Clear the browser adapters.
if (Request.UserAgent.Contains("AppleWebKit"))
{
Request.Browser.Adapters.Clear();
}
2. Change the client target.
if (Request.UserAgent.Contains("Safari"))
{
Page.ClientTarget = "uplevel";
}
The default user agent for Google Chrome is as follows. It contains both Safari and WebKit, so I doubt the targeted user agent is a significant difference.
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.X.Y.Z Safari/525.13.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我已经自己“解决”了这个问题,因为显然没有人知道。实际的答案是 ASP.NET 将使用 WebKit 的浏览器识别为“下层”浏览器,这意味着它们无法处理现代 HTML 或 JavaScript。作为补偿,ASP.NET 使用“适配器”以不同方式呈现菜单标记。
在情况2.(更改客户端目标)中,客户端被迫被识别为
“uplevel”
浏览器。因此,菜单会正常呈现,就像 Internet Explorer 或 FireFox 一样。在情况1.(清除浏览器适配器)中,客户端仍然被视为下层,并且插入适配器以补偿所谓的旧浏览器,但在可以使用之前,所有适配器被冲洗掉。
因此,我得出结论,技术上方法2.更好,因为
Page_Load
方法而不是Page_PreInit
方法上使用,从而允许将其添加到母版页中,而无需继承的基页。Alright, I have "solved" this on my own because no one else apparently knows. The actual answer is that ASP.NET recognizes browsers using WebKit as "downlevel" browsers, meaning they are supposedly incapable of processing modern HTML or JavaScript. To compensate, ASP.NET renders the menu markup differently using "Adapters."
In situation 2. (changing the client target), the client is forced to be recognized as an
"uplevel"
browser. Consequentially, the menu is rendered normally, as it would be for Internet Explorer or FireFox.In situation 1. (clearing the browser adapters), the client is still seen as downlevel and an adapter is inserted in order to compensate for the supposedly old browser, but before it can be used, all of the adapters are flushed out.
Thus, I conclude that technically method 2. is better because
Page_Load
method rather than thePage_PreInit
method, thereby allowing it to be added into a Master Page without need of an inherited base page.