且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检测Firefox的用户代理?

更新时间:2023-11-29 20:56:58

据Mozilla基金会的文件,火狐必须由用户代理被识别时,它的包含字符串的火狐/ XYZ并没有包含字符串的组件Seamonkey / XYZ的。更多信息:

https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent

I am working on an application where I am required to make legacy code, which has been designed primarily for Internet Explorer, work with Firefox.

The problem I have hit is iframes nested within a table structure do not expand to the full height of the table cell. Due to the size of the web application the decision has been made to create a JavaScript shim to address this issue instead of making mark-up changes. This shim will only be included on the page if the browser is Firefox as the problem does not exist within other browsers I have tested.

So my question is:

Using a classic ASP VBScript function how can I identify Firefox browsers, this should include any edge cases?

So far I have the following which checks the user agent for the string value "Firefox". Are there any cases where this would not work?

function IsFirefox()

    dim userAgent : userAgent = Request.ServerVariables("HTTP_USER_AGENT")
    dim locationOfFirefox : locationOfFirefox = InStr(1, userAgent, "Firefox", 1)

    IsFirefox = (locationOfFirefox > 0)

end function

According to a document from the Mozilla Foundation, Firefox must be identified by the user agent when it contains the string "Firefox/xyz" and does not contain the string "Seamonkey/xyz". More information:

https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent