browser-feature-detection

How to detect `focusin` support?

删除回忆录丶 提交于 2019-11-30 06:49:38
Thanks to Perfection kills , we can use the following JavaScript to detect event support: function hasEvent(ev) { var elem = document.createElement('a'), type = 'on' + ev, supported = elem[type] !== undefined; if (!supported) { elem.setAttribute(type, 'return;'); supported = typeof elem[type] === 'function'; } elem = null; return supported; } This works for about the only time I need it: detecting mouseenter support; hasEvent('mouseenter') will return false in Chrome, Firefox, etc., as it should. But now I'm trying to "fix" browsers that don't support the focusin and focusout events. According

How can I feature-detect CSS filters?

若如初见. 提交于 2019-11-30 03:29:09
In some browsers, including Chrome stable, you can do this: h3 { -webkit-filter: grayscale(1); filter: grayscale(1); } And wouldn’t you know it, the h1 will be rendered completely in grayscale. Everything old is new again . Anyway — does anyone know of any way to feature-detect for this? I need to be able to apply other styles if fil filter won’t work. Sepehr So called UPDATED answer: As the OP mentioned a good point I'm updating the answer but this does not have anything related or in contradict with my previous answer, this is simply a browser detection. Alan H. mentioned that IE, prior to

Detect if browser supports data uri scheme with iframes

蹲街弑〆低调 提交于 2019-11-29 11:11:57
Internet Explorer does not support the data uri scheme for iframe urls (see http://msdn.microsoft.com/en-us/library/cc848897%28v=vs.85%29.aspx ). Other browsers do. As browser detection is loaded with testing and future-proofing problems, I want to use feature detection to work around this issue. So: how can I detect whether or not a browser supports the data uri scheme for iframes? This solution by Kevin Martin is tested and seems to be giving the correct result in IE, FF and Chrome: function iframeDataURITest(src) { var support, iframe = document.createElement('iframe'); iframe.style.display

Reliably detecting <img> tag support for SVG

烈酒焚心 提交于 2019-11-29 03:48:39
I'm currently doing some redesign of a website, basically just upgrading it to a more up-to-date look and trying to make it as resolution independent as possible, and in the name of resolution independence I figured I'd try to use SVG images in the design where the browser supports SVG images in <img> tags. The reason I want to stick to just using SVG in <img> tags rather than using some more ambitious solution is that AFAIK Chrome, Opera and Safari all support it and FF4 seems like it may finally get it as well combined with the fact that the entire site is built on a custom CMS which would

jQuery 1.9 browser detection

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 05:27:02
In earlier versions, I used to test if I should be triggering popstate manually on page load, because Chrome triggers it right after load, and Firefox and IE do not. if ($.browser.mozilla || $.browser.msie) { $(window).trigger('popstate'); } Now that they dropped the browser object in 1.9, how should I test for these browsers? Or how do I figure if I need to popstate on page load or not? The code is: $(function(){ $(window).on('popstate', popState); // manual trigger loads template by URL in FF/IE. if ($.browser.mozilla || $.browser.msie) { $(window).trigger('popstate'); } }); Update Went for

Reliably detecting <img> tag support for SVG

廉价感情. 提交于 2019-11-27 17:50:45
问题 I'm currently doing some redesign of a website, basically just upgrading it to a more up-to-date look and trying to make it as resolution independent as possible, and in the name of resolution independence I figured I'd try to use SVG images in the design where the browser supports SVG images in <img> tags. The reason I want to stick to just using SVG in <img> tags rather than using some more ambitious solution is that AFAIK Chrome, Opera and Safari all support it and FF4 seems like it may

How to detect HTML5 audio MP3 support?

旧城冷巷雨未停 提交于 2019-11-27 11:54:40
I know how to check in Javascript if HTML5 audio playback is available. But how do I specifically check if MP3 audio playback is available, as IE9 and Chrome support it, while Firefox and Opera do not. keyboardP You could either check the User-Agent and see what browser is being used or you could test support with Javascript. var a = document.createElement('audio'); return !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, '')); I got the above code from this page . return !!(a.canPlayType) is better because (some recent versions of)Firefox not supports mp3 and a.canPlayType('audio

New Webkits convert decimal comma to ~ dot and vice versa in number-type inputs. Javascript name of that browser feature?

淺唱寂寞╮ 提交于 2019-11-27 09:21:26
I found a most peculiar browser feature in the latest Chrome (35; Win/Android/iOS) and Safari (7; iOS) versions. If you have a math form with input type="number" and enter a number with a decimal comma, the browsers do the calculations with the number as if the comma were a dot. And if you enter numbers with decimal dots, they do their normal calculations, but the resulting figure is displayed with a decimal comma. That is, in my European (i.e. Dutch) version. I don't know about American versions. If you would find that hard to believe, I made a demo to demonstrate it: <!DOCTYPE html> <html>

iPad version detection in JavaScript

喜欢而已 提交于 2019-11-26 21:33:55
问题 Is it possible to check for the iPad version (1 or 2) in a web application? As the user agent looks identical (see http://www.webtrends.com/Support/KnowledgeBase/SolutionDetail.aspx?Id=50140000000acbiAAA) a standard check by browser does not work here. Can we check for features (like the gyroscope) in JavaScript which are only available in version 2? 回答1: Please try this fiddle. It detects version of iPad by gyroscope availability. As you can see in Safari Developer Library, event

Check browser CSS property support with JavaScript?

眉间皱痕 提交于 2019-11-26 19:56:50
Is it possible in JavaScript to know if a CSS property is supported by the client browser? I'm talking about the rotation properties of CSS3. I want to execute some functions only if the browser supports them. I believe you can do it this way: if ('WebkitTransform' in document.body.style || 'MozTransform' in document.body.style || 'OTransform' in document.body.style || 'transform' in document.body.style) { alert('I can Rotate!'); } termi There is a new DOM API CSS.supports for that purpose. FF, Opera (as supportsCSS) and Chrome Canary already implement this method. For cross-browser