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

232
Vistas
window.open(url) method reloads the page again & agan

I have a problem , I need a function/program when specific screen reaches it relod the other window but when I open the window it reloads again & again. I am using window.open() method to open other link but if you know other better solution I am ready to discuss.



function redirect() {
    let deviceWidth = document.documentElement.clientWidth;

    if ((deviceWidth > 320) && (deviceWidth < 720 )) {
        mobile();
    }

    else if ((deviceWidth > 721) && (deviceWidth < 1199)) {

        tablet();
    }

    else if (deviceWidth > 1200)  {

        desktop();
    }
    else {
        console.log("something wrong");
    }






    function mobile() {
        // window.location.replace("./mobile.html");
        let win = window.open('./mobile.html',"_self","",true)
            win.focus();
            
            console.log('mobile');
        
    }
    function tablet() {
        // window.location.replace("./tablet.html");
        let win = window.open('tablet.html',"_self","",true)
            win.focus()
            
            console.log('tablet');
        
    }
    function desktop() {
        // window.location.replace("./index.html");
        

        let win = window.open('index.html',"_self","",true)
        win.focus();
        console.log('desktop');

        
    }
}
redirect();




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

0

My first thought would be to check if these functions also exist on the page that is being loaded over and over. If so, delete your call to redirect() in the mobile, tablet, and index.html pages. This would cause redirect() to be called recursively.

If you need to keep the redirect() function in place, you're more than likely going to need to factor in some if statements. For instance, you can grab the referrer header once you've redirected, and if it's from any of those pages, you can break the loop.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I got the answer. The problem was that I was calling the function to open a new html file even if my window is already opened that html file which causes it reapition. for example: If currently I am in the mobile.html then I was making a mistake by calling it even though it is open.

windown.opein("mobile.html")

which causes it recursive.

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