Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

230
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda