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

136
Visualizações
How to Bring Desktop Browser Back to Forefront When Minimized through a Push Notification

I'm trying to bring desktop browsers such as Firefox, Chrome, Brave, etc to the forefront when a push notification is clicked.

EDIT: As soon as I posted this comment I thought of removing event.preventDefault(); and that worked to do the popup, but it opens in a new tab and doesn't get selected.

As it stands with this code, the page opens but it opens in a new tab that is not selected. Let's say I minimize Firefox and start working in notepad or GIMP; I want to click a push notification then have it bring the browser back to forefront with the new tab selected aswell.

Jquery or Javascript will work if I can accomplish my objective.

Also, I don't want this to open a new browser instance; I want the code to use the existing browser instance but pop forward with my selected link.

Here's my code so far, and it doesn't accomplish my goal:

function sendPush(pushTitle, pushBody, pushUrl) {
    
    // pushTitle is the title, pushBody is the body, pushUrl is the link that will be opened when the push notification is clicked

    // check if the browser supports push notes
    if (!("Notification" in window)) {
      console.log("This browser does not support desktop notification. To get push notifications use a chromium based browser or mozilla based browser");
    }
    
    // generate and send the push notification
    else if (Notification.permission === "granted") {
      var notification = new Notification(pushTitle,{ 
        onshow: null, 
        onerror: null, 
        onclose: null, 
        title: pushTitle, 
        dir: "auto", 
        lang: "", 
        body: pushBody, 
        tag: "", 
        icon: pushIcon });
    }
    
    // add the onclick listener to make the notification interactive and open a link
    if (notification){
        notification.onclick = function(event) { 
            // if I remove this it works but doesn't select the new tab
            //event.preventDefault(); 
            // I tried removing _blank and that didn't work
            window.open(pushUrl, '_blank');
            // I tried doing window.focus() but it doesn't work
            window.focus();
        }
    }
}

How can I bring the browser window back to forefront if it's in the background from a push notification?

I have searched on google and duckduckgo extensively but not found anything that works. Is this even possible?

EDIT: if I remove event.preventDefault(); it brings the window to forefront but the tab is not selected when the window pops up. Any way to open a new tab AND pop up at the same time?

about 4 years ago · Juan Pablo Isaza
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