0

Im working on a Test AB on Adobe Target.

I have this code that works perfect on chrome but When i try it on Internet explorer I get an error.

MY CODE:

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

ERROR: Object doesn't support property or method 'includes'

I try with indexOf but i get another error: Unable to get property 'indexOf' of undefined or null reference

I can not use polymer because I don´t have access to the original code. Is there anyway I can fix this code so it could work on Internet explorer?

Miguel bastidas
  • 67
  • 1
  • 1
  • 9

1 Answers1

1

It looks like it is necessary to check whether eventData.newURL is null:

if (eventData && eventData.newURL && eventData.newURL.includes('#mypage-example')) { 
   console.log('I  am on my page');
   funcionCarga();
}
StepUp
  • 36,391
  • 15
  • 88
  • 148
  • Thank You!!!!! I can not see the error. But the javascript code I want to inject on the console is not working. My functionCarga() code is injected perfectly on chrome with the code you gave me but it is not working on IE. ¿Do you know what could it be? sorry for my bad english – Miguel bastidas Jan 10 '20 at 13:58
  • @Miguelbastidas [.includes() not working in Internet Explorer](https://stackoverflow.com/questions/36574351/includes-not-working-in-internet-explorer) – StepUp Jan 10 '20 at 14:02
  • @Miguelbastidas I am glad to help you! [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) :) – StepUp Jan 13 '20 at 10:19