【问题标题】:Unable to get property 'indexOf' of undefined or null reference无法获取未定义或空引用的属性“indexOf”
【发布时间】:2020-04-28 02:19:14
【问题描述】:

我正在开发 Adob​​e Target 上的测试 AB。

我的这段代码在 chrome 上运行完美,但是当我在 Internet Explorer 上尝试时出现错误。

我的代码:

function hashHandler(eventData) {
      if (eventData.newURL.includes('#mypage-example')) { 
          console.log('I  am on my page');
          funcionCarga();
      }
  }
      window.addEventListener('hashchange', hashHandler, false);

错误:对象不支持属性或方法“包含”

我尝试使用 indexOf,但出现另一个错误:无法获取未定义或空引用的属性 'indexOf'

我不能使用聚合物,因为我无法访问原始代码。无论如何我可以修复此代码以便它可以在 Internet Explorer 上运行吗?

【问题讨论】:

标签: javascript hash include indexof


【解决方案1】:

看来需要检查eventData.newURL是否为null

if (eventData && eventData.newURL && eventData.newURL.includes('#mypage-example')) { 
   console.log('I  am on my page');
   funcionCarga();
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-08-01
  • 2016-08-16
  • 2017-05-18
  • 1970-01-01
  • 2014-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多