Closed pento closed 9 years ago
This little snippet seems to accurately detect if emoji is supported in a browser:
if (!String.fromCodePoint) { /*! * ES6 Unicode Shims 0.1 * (c) 2012 Steven Levithan <http://slevithan.com/> * MIT License **/ String.fromCodePoint = function fromCodePoint () { var chars = [], point, offset, units, i; for (i = 0; i < arguments.length; ++i) { point = arguments[i]; offset = point - 0x10000; units = point > 0xFFFF ? [0xD800 + (offset >> 10), 0xDC00 + (offset & 0x3FF)] : [point]; chars.push(String.fromCharCode.apply(null, units)); } return chars.join(""); } } function doesSupportEmoji() { var context, smiley; if (!document.createElement('canvas').getContext) return; context = document.createElement('canvas').getContext('2d'); if (typeof context.fillText != 'function') return; smile = String.fromCodePoint(0x1F604); // :smile: String.fromCharCode(55357) + String.fromCharCode(56835) context.textBaseline = "top"; context.font = "32px Arial"; context.fillText(smile, 0, 0); return context.getImageData(16, 16, 1, 1).data[0] !== 0; }
Copied from this snippet.
This little snippet seems to accurately detect if emoji is supported in a browser:
Copied from this snippet.