12

I'm aware of the fact that the FileReader Object is not available in Safari 5.0.5. I have a script that uses it and thought that i'd just be able to detect whether the object exists to run some alternate code, as is suggested here,

http://www.quirksmode.org/js/support.html

So my code is,

if( FileReader )
{
    //do this

}else{

    //the browser doesn't support the FileReader Object, so do this
}

The problem is, i've tested it in Safari and once it hits the if statement i get this error and the script stops running.

ReferenceError: Can't find variable: FileReader

So obviously that's not the best way to deal with it then? Any idea why this doesn't work?

2
  • is FileReader supported in Safari 5.1.5? I'm getting error in 5.1.5 also. Commented Apr 6, 2012 at 15:47
  • No. Possible in 5.2: caniuse.com/filereader Commented May 9, 2012 at 11:41

3 Answers 3

30

I believe in your case you can get away with a simpler check:

if(window.FileReader) {
   //do this
} else {
   //the browser doesn't support the FileReader Object, so do this
}

check for the type if you really wanna be granular and picky.

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

1 Comment

Agreed. You must ask for window.FileReader otherwise an Uncaught ReferenceError will occur (observed on Android 2.3)
7

You can write if (typeof FileReader !== "undefined")

You can also use the Modernizr library to check for you.

Comments

2

Or you can do something like this.

if('FileReader' in window) {
    // FileReader support is available
} else {
    // No support available
}

Comments

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.