How to open a page in the same tab with Javascript?

Asked

Viewed 4,347 times

0

I have this script ajax that refreshes the screen and calls the notifyMe() and the notification is displayed. But I noticed that clicking opens the page in another tab. I want when clicked on the notification to open in the same tab as this notification and not to open a new one.

<script>
    // request permission on page load
document.addEventListener('DOMContentLoaded', function () {
  if (!Notification) {
    alert('Desktop notifications not available in your browser. Try Chromium.'); 
    return;
  }

  if (Notification.permission !== "granted")
    Notification.requestPermission();
});

function notifyMe() {
  if (Notification.permission !== "granted")
    Notification.requestPermission();
  else {
    var notification = new Notification('DIAZERO SECURITY', {
      icon: '<?php url(); ?>/favicon.png',
      body: "Sua solicitação foi atualizada!",
    });

    notification.onclick = function () {
      window.open("<?php url(); ?>/solicitacao/<?php echo $a; ?>");      
    };

  }

}
</script>

1 answer

1


Use the window.location.href in place of window.open:

window.location.href = "<?php url(); ?>/solicitacao/<?php echo $a; ?>";
  • opa very good solved thank you very much ^^

Browser other questions tagged

You are not signed in. Login or sign up in order to post.