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

128
Views
Is there any way to shift to previous browser tab using javascript?

Im working on a VBCS application and i have a requirement to download files onto a new tab.

Im running an application, and after a few operations I end up at the last tab (circled in black). I need to close the red circled tab because it is a duplicate of the blue circled tab. Is there any way i can go back to the red tab and call

window.close()

on it? All the tabs are being opened through my application only. IS it even possible to navigate back to the tab? Also i cannot close the blue circled tab because even though the red circled tab is a dulicate of it, the red tab is reloading the page and the blue tab is already loaded page.

Any help is very much appreciated. Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can communicate between the tabs using localStorage (actually there might be even a better API for this BroadcastChannel ). Anyway, this is a sketch of a solution which is open for some bugs but if you like it , it can be improved.

<h2>page 1</h2>
<button onclick="close_others();">close others</button>
<script>
    window.id = Math.random();
    var key = "close-but-me"

    function close_others() {
        localStorage.setItem(key, window.id);
        window.setTimeout(function() {
            localStorage.removeItem(key);
        }, 2000)
    }

    setInterval(function() {
        console.log(localStorage.getItem(key))
        if (localStorage.getItem(key) && localStorage.getItem(key)!=window.id) {
            window.close();
        } 
    }, 1000)
</script>
<h2>page 2 - SAME code</h2>

<button onclick="close_others();">close others</button>
<script>
    window.id = Math.random();
    var key = "close-but-me"

    function close_others() {
        localStorage.setItem(key, window.id);
        window.setTimeout(function() {
            localStorage.removeItem(key);
        }, 2000)
    }

    setInterval(function() {
        console.log(localStorage.getItem(key))
        if (localStorage.getItem(key) && localStorage.getItem(key)!=window.id) {
            window.close();
        } 
    }, 1000)
</script>
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!