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

226
Views
How to close current browser window and open new window using JavaScript

I am trying to close the current windows brower and open a new one. Currently, it opens a new window on each click which is not correct.

Not sure where am I doing wrong in this?

Can someone point me right direction?

<div id="oWrapper" style="display: none;">
    <div id="oIn"></div>
</div>

 $(document).ready(function () {          

        var isIE = false || !!document.documentMode;

        if (isIE) {
            var tURL = 'microsoft-edge:' + '@Url'.replace(/amp;/g, '');
            var openE = document.querySelector('#oIn');
            openE.href = 'microsoft-edge:' + document.URL;
            var oWrapper = document.querySelector('#oWrapper');
            oWrapper.style.display = 'block';
            window.location.replace(tURL);
        }
        else {           
            var params = [
                'height=' + screen.height,
                'width=' + screen.width,
                'scrollbars=yes',
                'resizable=yes',
                'location=no'
            ].join(',');

            var Obj;

            function ModalPopUp() {
                Obj = window.open('@Url'.replace(/amp;/g, ''), "_blank", params);
                Obj.moveTo(0, 0);

                Obj.focus();
                LoadModal();
            }

            function LoadModal() {
                var Div = document.getElementById("oIn");
                Div.style.display = "block";
            }

            function OnUnload() {                 
                if (false == Obj.closed) {
                    Obj.close();
                }
            }
            window.onunload = OnUnload;
            ModalPop();
        }
    });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It seems like you only try to Obj.close upon window.onunload, instead of before a new modal is opened.

Try:

function ModalPopUp() {
    if (Obj) Obj.close(); // close existing modal if it exists
    
    Obj = window.open('@Url'.replace(/amp;/g, ''), "_blank", params);
    Obj.moveTo(0, 0);

    Obj.focus();
    LoadModal();
}
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!