Check for HTML5 with JS
Check for HTML5 with JS
我有一个页面,其中包含一些JS来更新浏览器历史记录(pushState()
,使用HTML5)。由于IE8不支持HTML5,用户被告知页面包含错误。虽然这并没有削弱页面的功能,但它看起来不太专业,所以我想知道是否有一个检查,看看用户的浏览器是否支持HTML5之前运行这段代码?
<script type="text/javascript">
/** Update history.state() (for back/forward links) */
var object = {
ajax_string: '<?php echo make_ajax_string(); ?>',
security: '<?php echo wp_create_nonce('updated-page-nonce'); ?>',
};
window.history.replaceState(object, '<?php echo $post->post_title; ?>', '<?php echo get_permalink($post->ID); ?>');
</script>
谢谢。
您可以在运行代码之前检查replaceState
方法是否可用:
if(window.history.replaceState) {
//Your code
}
如果replaceState
是undefined
(这将是在浏览器中不支持它的情况下),则语句计算为false
,代码不执行
我建议使用Modernizr
您可以使用Modernizr检查新的HTML5历史api (pushState
, replaceState
, popState
)是否被浏览器支持,或使用
我建议:
if (!!(window.history && history.replaceState)) {
// has replaceState support
}
相关文章:
- timeago.js with datatable and PHP
- using require.js with FB SDK
- Require JS with Knockout组件正在查找路径不正确的JS文件
- JS with SVG:围绕其中心旋转SVG元素
- Node JS with C++ integration
- leafleat-editable.js with mapbox.js
- Ember.js with EmberFire Object - 如何使用数组属性
- Using moment.twitter.js with requirejs
- 使用 Enquire.js with Vue.js 查询浏览器的大小
- Polymer JS with Embedded CSS
- Node.js with Geddy:geddy.string.uuid(x) 是否确保字符串是唯一的
- Ember.js with Cloudkit JS
- Using typeahead.js with jquery ajax call
- Angular.js with Jade 和 Express - 数据绑定不起作用
- Node.js with Webstorm -
- BrainTree.js with AngularJS and customVariables
- Backgrid.js with Backbone
- Backbone.js with MVC 3 and ViewModels
- Zombie.js with Behat and Mink
- 从Blender导出到Three js with Textures