Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

258
Views
El uso de `window.location.hash.includes` arroja "El objeto no es compatible con la propiedad o el método 'incluye'" en IE11

Estoy revisando la URL para ver si contiene o incluye un ? en él para controlar el estado pop hash en la ventana. Todos los demás navegadores no tienen problemas, solo IE.

El depurador me da este error cuando trato de cargar de esta manera:

El objeto no admite la propiedad o el método ' includes '

No recibo ningún error cuando cargo la página a través de popstate.

 $(document).ready(function(e) { if(window.location.hash) { var hash; if(window.location.hash.includes("?")) { alert('I have a ?'); hash = window.location.hash.substring(window.location.hash.indexOf('#') + 0,window.location.hash.indexOf('?')); }else { hash = window.location.hash; }; if (hash=="#DRS" || hash=="#DRP" || hash=="#DFFI" || hash=="#DCI" || hash=="#DCP" || hash=="#DRP" || hash=="#DRMA" || hash=="#EICS" || hash=="#ORG"){ $(hash+'Content').addClass('pageOn').removeClass('pageOff'); }else { $('#homeContent').addClass('pageOn').removeClass('pageOff'); }; } else { $('#homeContent').addClass('pageOn').removeClass('pageOff'); } $(window).on('popstate', function() { var hash; if(window.location.hash.includes("?")) { hash = window.location.hash.substring(window.location.hash.indexOf('#') + 0,window.location.hash.indexOf('?')); }else { hash = window.location.hash; }; if (hash=="#DRS" || hash=="#DRP" || hash=="#DFFI" || hash=="#DCI" || hash=="#DCP" || hash=="#DRP" || hash=="#DRMA" || hash=="#EICS" || hash=="#ORG"){ $(this).navigate({target: $(hash+'Content')}); if(window.location.hash.includes("?")) { }else{ location.href = location.href+'?'; } }else { $(this).navigate({target: $('#homeContent')}); }; }); });
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

De acuerdo con la página de referencia de MDN , las includes no son compatibles con Internet Explorer. La alternativa más simple es usar indexOf , así:

 if(window.location.hash.indexOf("?") >= 0) { ... }
over 4 years ago · Santiago Trujillo Report

0

IE11 implementa String.prototype.includes, entonces, ¿por qué no usar el Polyfill oficial?

 if (!String.prototype.includes) { String.prototype.includes = function(search, start) { if (typeof start !== 'number') { start = 0; } if (start + search.length > this.length) { return false; } else { return this.indexOf(search, start) !== -1; } }; }

Fuente: fuente de relleno polivinílico

over 4 years ago · Santiago Trujillo Report

0

Agregar import 'core-js/es7/array'; a mi polyfill.ts me solucionó el problema.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!