3

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
Jonathan
  • 1,833
  • 13
  • 15
  • 4
    Well, derived browsers won't work. You really want the rendering engine ID (Gecko), not the browser brand name. – MSalters Dec 11 '13 at 12:51
  • do not try to identify the browser but the functions of a browser. i.e. the Internet Explorer 11 on a win 8.1 machine will give this user Agent string: "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; MDDRJS; rv:11.0) like Gecko" so when you look for "Gecko" to identify Firefox your script will fail – ulluoink Dec 12 '13 at 06:40
  • Your code is fine but risky. What if future build of Chrome will introduce this same bug/behavior? You realy better solve this client side, find workaround to the nested iframes e.g. use ordinary `
    ` elements and load their contents using simple jQuery `.load()` or `.get()` methods. These days `` for internal pages are REALLY not needed.
    – Shadow The GPT Wizard Dec 12 '13 at 09:06
  • @ShadowWizard unfortunately I am working on a legacy system which has `10246 iframes` found in `3589 files` so re-factoring the code to work without iframes is really not possible at this time. – Jonathan Dec 12 '13 at 16:12
  • @Jonathan you'll be surprised how powerful jQuery can be. You can convert all iframes to `
    ` elements with the same contents **at run time**. You won't have to touch single line of HTML code.
    – Shadow The GPT Wizard Dec 12 '13 at 16:20
  • 1
    You might have the same issue with [this](http://stackoverflow.com/questions/2490452/using-javascript-to-detect-browser-type). – Stuart Dec 13 '13 at 03:46

1 Answers1

1

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

MetalicUNQ
  • 26
  • 2
  • 5