2

First of all this is very similiar to: Workaround for file input label click (Firefox)

but the provided solution is not working in jQuery 1.9+

The $.browser variable dosn't exist anymore because now we have to do feature detection.

I would very much like to detect the feature that I need but there seems to be no such support in jQuery. Browser detection is gone, feature detection seems not able to detect what I need, is there a good solution out there? A Modernizr solution would be appreciated aswell and also plain-vanilla-js solution is accepted

Thanks for your help.

2
  • If you mean reversing the order, that is not a solution. Commented Feb 19, 2013 at 16:42
  • I meant using the label click -> input click trigger solution, but that would result in double file dialogs in other browsers. I can't think of a way to detect support for this, so i'd suggest just looking at the useragent and detecting the specific browser and version(s) that is having this issue. Commented Feb 19, 2013 at 16:43

2 Answers 2

3
if ( window.mozIndexedDB !== undefined ) {
   //do firefox things
}

This will only return true in Firefox, afaik.

Example test:

if ( window.mozIndexedDB !== undefined ) {
   alert('You are using Firefox');
}

You can try looking at window.navigator.userAgent but I don't recommend it, a bunch of other browsers identify as Mozilla, see this question for some examples: Why Does “navigator.userAgent” in javaScript returns the String “Mozilla” when tried in a google chrome borwser?

Sign up to request clarification or add additional context in comments.

3 Comments

My Firefox returns undefined when accessing window.Mozilla
is this any better then navigator.userAgent.indexOf('Firefox')!==-1 ?
If they're both in place and correct, no practical difference, but some devices send weird user agent info.
0

Not the best practice, but why don't you try the jQuery Migrate plugin? It brings back $.browser, aswell some other removed features.

1 Comment

Because that's another 16.7kb just to check wether this is a firefox browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.