Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
Uncaught ReferenceError on jQuery script

When I try to run this script

window.onpopstate = function(popEvent) {
    let urlPath = window.location.pathName;
    let slash = page.lastIndexOf("/");
    let page = urlPath.substr(slash+1);
    let $tab;

    if (page = '') {
        $tab = $("#tabs .tab:first-of-type");
        page = $tab.attr("href");
    }

    else { $tab = $("#tabs .tab[href="+CSS.escape(page)+"]") }

    $tab.addClass("current").siblings().removeClass("current");

    $.ajax({url: "subpages/"+page, function(html) {
        $(".append").html(html);
    } });
}

I’m getting the error message:

foo.js:38 Uncaught ReferenceError: Cannot access 'page' before initialization at window.onpopstate (foo.js:38:15)

I don’t really get what’s the problem.

Could someone help me out?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This error was caused only by mistyping: page → urlPath

window.onpopstate = function(popEvent) {
    let urlPath = window.location.pathName;
    let slash = urlPath.lastIndexOf("/");  // HERE
    let page = urlPath.substr(slash+1);
    let $tab;

    if (page = '') {
        $tab = $("#tabs .tab:first-of-type");
        page = $tab.attr("href");
    }

    else { $tab = $("#tabs .tab[href="+CSS.escape(page)+"]") }

    $tab.addClass("current").siblings().removeClass("current");

    $.ajax({url: "subpages/"+page, function(html) {
        $(".append").html(html);
    } });
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda