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')}); }; }); });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) { ... }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
Agregar import 'core-js/es7/array'; a mi polyfill.ts me solucionó el problema.