读书人

Android 2.2,2.3 浏览器不支持XPATH的

发布时间: 2012-11-23 00:03:43 作者: rapoo

Android 2.2,2.3 浏览器不支持XPATH的对策

之前做了一个smartphone的网站:http://cashing-navigator.net ,是关于融资类的网站

但是我的android手机上,检索不出结果

用2.3的版本也不能,

Android4.1 和 iphone均可以正常使用

后来找了好多资料,发现原来是浏览器不支持XPATH。


执行下面的语句时,

document.evaluate(path, xmlDom, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

try catch 后报以下错误。

ReferenceError:XpathResult is not defined


---------------------------解决办法----------------------------------

参照:https://github.com/levand/domina/issues/12


添加以下代码就可以用了

<script type="text/javascript">      /* Android 2.x claims XPath support, but has none.  Force non-native         XPath implementation in this case */      if (document.implementation           && document.implementation.hasFeature           && document.implementation.hasFeature("XPath",null)           && !document.evaluate) {        window.jsxpath = {          targetFrame: undefined,          exportInstaller: false,          useNative: false, /* force non-native implementation */          useInnerText: true        };      }    </script>    <!-- Non-native XPath implementation for IE and Android 2.x -->    <script type="text/javascript" src="js/xpath.js"></script>

要引用的xpath.js 参照这个网站

http://www.llamalab.com/js/xpath/



读书人网 >Android

热点推荐