检测移动设备是否支持Ajax的标准方法是什么?如果它不受支持,我需要用静态内容替换Ajax内容。做了一些谷歌搜索,但没有找到太多。
有任何建议或示例吗?
谢谢!
答案 0 :(得分:0)
我不知道必然存在标准方式 - 您可以查看某些使用WURFL的API /库/框架。
如果WURFL过于沉重,那么这就是UCLA移动Web框架迄今为止所开发的内容(来自https://github.com/ucla/mwf/blob/feature/core/root/assets/js/core/device.js):
/**
* Determine if device supports AJAX. This attempts to create an XHR object
* of the standard type and ActiveXObject varieties and, if any succeed, then
* it returns true.
*/
this.hasAJAX = function(){
var xhr = null;
try { xhr = new XMLHttpRequest(); } catch (e) {}
try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
return xhr != null;
}