browser-feature-detection

Downsides of using the navigator object / user-agent sniffing for detecting IE versions

百般思念 提交于 2019-12-10 19:18:39
问题 With the release of jQuery 2.0, there has been a lot of talk about how to identify if the user is using an IE version which is supporting it or not (jQuery 2.0 only supports IE9 and later). My question is why a solution like this: var ie = (function(){ var undef, v = 3, div = document.createElement('div'), all = div.getElementsByTagName('i'); while ( div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->', all[0] ); return v > 4 ? v : undef; }()); is preferred over looking at the

javascript detect desktop touch and mouse support

陌路散爱 提交于 2019-12-10 19:06:06
问题 How should touch-enabled devices be differentiates between pure touch and ones that also have a mouse? (like some of today's laptops) There is a need to give all mouse functionality a priority in an application, and if the device running the app has only touch support, to change the functionality. If a touch-device also has a mouse pointer, logic suggests the app should consider that device as a normal desktop, and might add touch support as well, but the styling itself should respond to

What is the most reliable way to detect a mobile device using Modernizr?

雨燕双飞 提交于 2019-12-09 19:01:00
问题 I am developing a responsive site and I have been asked to swap any freephone numbers on our site to the landline equivalent when a user is browsing on a mobile device. What is the most reliable way to detect if a user is on a mobile device using the Modernizr library (or any other library)? I am aware of Modernizr.touch and also Modernizr.geolocation. When the two are combined in an if(Modernizr.touch && Modernizr.geolocation) statement they are a good indicator of whether you are on a

How to identify buggy behavior in “input” event without browser detection?

烈酒焚心 提交于 2019-12-08 16:37:48
问题 I'll start with the question. When a specific browser has a buggy implementation of a feature and your javascript needs to know whether the current browser has that buggy implementation or not so it can use an alternate strategy, how do you figure out if the implementation is buggy without doing browser type sniffing (which is generally considered bad)? Here's the whole situation. I was working on some code that wants to use the "input" event for getting notifications of user changes to an

Detect viewport units (with modernizr or normal js) and serve appropriate stylesheet

北城以北 提交于 2019-12-06 07:19:31
I actually have an issue im trying to solve since 3 weeks. Im trying to test support for vw units and serve a seperate stylesheet when the browser doesnt support the unit I read the modernizr tutorials and am familiar with modernizr css detects but testing for vh units (viewport relative units) is something I didnt find on the net. So basically: Scenario 1: Browser supports vw unit then serve stylesheet A. Scenario 2: Browser doesnt support it then serve stylesheet B. I did find out that there is a non-core detect called Modernizr.cssvwunit but I honestly have no idea where to start or how to

Detect if iOS is using webapp

*爱你&永不变心* 提交于 2019-12-04 10:13:06
问题 I was wondering if it's possible to detect if an iOS user is using the webapp, or just visiting the normal way with safari browser. The reason I want to achieve is that on a iOS webapp when a user click on a link, he will get redirected to the Safari browser. So I'm using the following workaround to make him stay in the webapp(prevent the switching to safari browser). $( document ).on("click",".nav ul li a", function( event ){ // Stop the default behavior of the browser, which // is to change

/*@cc_on and IE6 detection

醉酒当歌 提交于 2019-12-04 09:24:53
When researching JavaScript conditional comments for IE, I stumbled upon @cc_on. This seems to work. However, the wikipedia entry on conditional comments provides the following code for more robust IE detections, specifically IE6: /*@cc_on @if (@_jscript_version > 5.7) document.write("You are using IE8+"); @elif (@_jscript_version == 5.7 && window.XMLHttpRequest) document.write("You are using IE7"); @elif (@_jscript_version == 5.6 || (@_jscript_version == 5.7 && !window.XMLHttpRequest)) document.write("You are using IE6"); @elif (@_jscript_version == 5.5) document.write("You are using IE5.5");

How to detect if browser support specified css pseudo-class?

允我心安 提交于 2019-12-04 06:25:46
What's concept of detecting support of any css pseudo-class in browser through JavaScript? Exactly, I want to check if user's browser supports :checked pseudo-class or not, because I've made some CSS-popups with checkboxes and needs to do fallbacks for old browsers. ANSWER: I'm found already implemented method of testing css selectors in a Modernizr "Additional Tests" . You can simply check if your style with pseudo-class was applied. Something like this: http://jsfiddle.net/qPmT2/1/ stylesheet.insertRule(rule, index) method will throw error if the rule is invalid. so we can use it. var

Javascript: How can I delay returning a value for img.complete

落花浮王杯 提交于 2019-12-03 20:21:18
问题 I've written a script to test for SVG support in the IMG tag: function SVGinIMG() { var SVGdata = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNzUiIGhlaWdodD0iMjc1Ij48L3N2Zz4%3D' var i = document.createElement('img'); i.setAttribute('src',SVGdata); return i.complete; } window.onload = function() { var hasSVG = SVGinIMG(); alert(hasSVG); } This does what I want, except that when I run the script in WebKit browsers the complete property doesn't

How can I feature-detect ES6 generators?

我与影子孤独终老i 提交于 2019-12-03 10:59:11
I'm really enjoying ES6 generators. Is there a way I can detect generator support in browsers? I know generators might not be in a lot of browsers (or possible no browsers at all) at the moment, but that's OK for my purposes. I tried: try { function *(){} } catch(err) { console.log("No generators"); } But it doesn't seem to work. How can I detect support for ES6 generators in browsers? Jeremy J Starcher One of the few times that eval is actually the right solution. For language construct changes, you need something like this: try { eval("(function *(){})"); } catch(err) { console.log(err);