继上一篇之后,我们来看看如何查看PhantomJS
支持哪些操作,官方在https://github.com/ariya/phantomjs/blob/master/examples/features.js 给了一下简单的示例
首先我们需要modernizr
,接着还要有这样一个脚本featrue
:
var feature, supported = [], unsupported = [];
phantom.injectJs('modernizr.js');
console.log('Detected features (using Modernizr ' + Modernizr._version + '):');
for (feature in Modernizr) {
if (Modernizr.hasOwnProperty(feature)) {
if (feature[0] !== '_' && typeof Modernizr[feature] !== 'function' &&
feature !== 'input' && feature !== 'inputtypes') {
if (Modernizr[feature]) {
supported.push(feature);
} else {
unsupported.push(feature);
}
}
}
}
console.log('');
console.log('Supported:');
supported.forEach(function (e) {
console.log(' ' + e);
});
console.log('');
console.log('Not supported:');
unsupported.forEach(function (e) {
console.log(' ' + e);
});
phantom.exit();
就会输出下面类似的结果:
Detected features (using Modernizr 2.8.3):
Supported:
flexboxlegacy
canvas
canvastext
touch
postmessage
websqldatabase
hashchange
history
draganddrop
websockets
rgba
hsla
multiplebgs
backgroundsize
borderimage
borderradius
boxshadow
textshadow
opacity
cssanimations
csscolumns
cssgradients
cssreflections
csstransforms
csstransitions
fontface
generatedcontent
localstorage
sessionstorage
webworkers
applicationcache
svg
inlinesvg
smil
svgclippaths
Not supported:
flexbox
webgl
geolocation
indexeddb
csstransforms3d
video
audio
果然是不支持geolocation
的
围观我的Github Idea墙, 也许,你会遇到心仪的项目