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

231
Views
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 answers
Answer question

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 Report

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 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!