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/



  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值