how to detect browser supports HTML5 microdata API - javascript

I use the following code to check for HTML5 microdata API support
function supports_microdata_api() {
return !!document.getItems;
}
but this is not working properly. How can I solve this problem?

Use Modernizr, so you can test it like this:
if (Modernizr.microdata) {
// Yay, microdata is supported!
}
Nonetheless Chrome and Safari don't seem to support this semantic syntax anymore.

Related

Recommended method for recognising Browser's HTML5 capability?

var isH5 = !! document.createElement('canvas').getContext
Would you say, that above JS code snippet is a good method of recognising a Browser's HTML5 capability?
Also see What is the !! (not not) operator in JavaScript? in case of IE quirks mode, it should still return false.
Update: Thanks for all the Modernizr links, we are using above recognising logic in conjunction with Modernizr already.
The better solution is to use something Modernizr to detection .Modernizr is an open source, MIT-licensed JavaScript library that detects support for many HTML5 & CSS3 features. If there isnt support, it returns false
if (Modernizr.canvas) {
// logic
} else {
// your message
}

How to show all plugins from Internet Explorer?

I am having some troubles on listing the plugins from IE plugins using Javascript like Panopticlick does.
I am using the plugin.name but it does not run on IE
Any suggestions or used code examples? Thank you
navigator.plugins will work for IE 11 but not for earlier IEs. More on IE and plugins can be read here. For earlier IEs, you will need to check for each plugin manually by trying:
try {
new ActiveXObject('aPluginName');
return true;
} catch(e) {
return false;
}
Main problem is, that plugins in IE are ActiveX based, which means each has its own API and there is no way you can check this in a general "catch-them-all" way. I found this link quite helpful.

Fallback for localstorage using modernizr

I am using localstorage for store data and it does not work will on IE7. So I am using modernizr for detecting its support to browser. But I want to add fallback on IE7. In IE7 case where can I find fallback function for localstorage for IE7. I mean what need to done when it falls into false condition.
if(Modernizr.localstorage) {
alert(0)
} else {
//function
}
Modernizr doesn't actually shim anything, it just detects wether or not a feature is supported. You can combine it with yepnope to conditionally load the local-storage-js polyfill to fallback appropriately.

how to ensure the browser can support **{get X() {}}**

i refuse to use __defineProperty__ and instead prefer the alternative syntax {get X() {}}
However this will not work on IE.
Aside from browser detection, what is the best way i can detect that a browser supports the newer syntax?
Edit: ok actually im not trying to detect IE in particular but redirect those "browsers that do not support get X(){} syntax" to notsupported.html. I believe that there's some way to do it and am working on it but in case someone already has this problem before and had a solution..
Edit 2: btw doesn't that mean that no one (erm other than me) uses the get X(){} syntax since its not supported by all (or not supported by the 5 major browsers yet) ?
As others have noted, you cannot force older (current!) browsers to accept newer syntax. And what would you do with browser detection? Use the old syntax for the old browsers and new syntax otherwise? Then you're writing the same code twice.
Decide on a set of browsers you need to support, determine what features they can all guarantee to you, then limit yourself to those features. That's how web development works.
You want to use an ES5 feature that is not commonly implemented.
You want to use syntax that common javascript interpreters cannot recognise.
There is no way to emulate it.
I recommend you just use
{
getX: function() { ... }
}
If you check the benchmark. Then you'll see using ES5 is 15 times slower. Just stick with ES3.
There is little you can do about this as there is no way to emulate getters in IE8.
Try this:
function browserSupportsGetterAndSetterSyntax() {
try {
return eval('({ get x() { return 3; }}).x') == 3;
} catch (e) {
return false;
}
}

Detect version of the plugin in Chrome browser

I have NPAPI plugin and I want to detect its version before I embed it into web page. If version is not the latest one I want to show some message that asks users to update the plugin.
Now it's implemented in the following way
if (navigator.mimeTypes && navigator.mimeTypes["application/myplugin"]) {
{
// some code here
if(navigator.plugins["myplugin"] && navigator.plugins["myplugin"].version >= latest_version) {
// we have the latest version (embed the plugin into web page)
document.write ("<object id='plugin'><embed ....></object>");
} else {
document.write ("Show message here");
}
// some code
}
The problem is that navigator.plugins["myplugin"].version works fine in Firefox but not in Chrome. Chrome doesn't expose version property. I can add my own property in NPAPI code, but I don't see the way I can use it before embedding the plugin into page.
Is there any workaround?
Thanks in advance, Andrew
I see a lot of plugins have version information in either the name or the description. You should be able to access that information before the embed.
I actually put the version number in the filename, rather than even the name or description. The reason for this is that if there are multiple plugins with the same name, description, and mimetypes Firefox will generally use the latest version. Older versions of firefox have been inconsistent in how they handle this, so I even usually put the np???_version.dll file in a version-specific subdirectory.
It is a little bit of a pain, but it works consistently the same way in every NPAPI browser.
You can create a JSAPI property of your plugin containing the version. This property returns the plugin's version when called from javascript. So when you try to insert/embed the plugin in the page, you can check through javascript to make the appropriate calls.

Categories