I’m trying to do object detection to prevent IE8 from throwing errors in the absence of new XMLSerializer() however I have been unsuccessful in finding a cross-browser way to approach the issue. I typically use object!='undefined' however I haven’t found a cross-browser way of implementing this.
Here are some of the ways I’ve tested in Firefox 10 and IE8…
if (typeof new XMLSerializer!='undefined') {alert('unsupported, 1');}
if (typeof new XMLSerializer()!='undefined') {alert('unsupported, 2');}
if (new XMLSerializer!='undefined') {alert('unsupported, 3');}
if (XMLSerializer!='undefined') {alert('unsupported, 4');}
if (window.XMLSerializer!='undefined') {alert('unsupported, 5');}
if (typeof XMLSerializer !== 'undefined') {alert('unsupported, 6');}
So how can we implement object detection for the XMLSerializer without triggering errors in unsupported browsers such as IE8?
You should be testing if it has it by this:
Here’s a fiddle demonstrating: http://jsfiddle.net/fGZbL/1/
Or the original fiddle I posted should work too (this tests truthiness of
window.XMLSerializer): http://jsfiddle.net/fGZbL/