1

I am writing a Javascript which runs in the browser using Tampermonkey.

The logic in the script is as follows. 1. Do some checks. 2. If a certain condition is met, then trigger an alert box in the browser.

Currently the alert box is shown in the browser tab, but amidst multiple tabs, the user does not notice the alert box till they navigate to the tab.

I am trying to figure out one or both of the following. 1. Bring the tab to the front i.e. focus on that tab. 2. Do something more aggressive than the alert box to catch user's attention. I thought of things such as playing sounds etc but it requires on user's speakers being on etc.

Any ideas on how to make this work would be greatly appreciated.

Vik G
  • 539
  • 3
  • 8
  • 22
  • This should answer your question: https://stackoverflow.com/questions/3311293/javascript-bring-window-to-front-if-already-open-in-window-open – JLowther Jan 28 '20 at 03:05
  • @JLowther I tried some of the suggestions on that post but they didnt' work well for me, Let me try them again and get back to you – Vik G Jan 28 '20 at 03:11
  • 1
    It seems like the conclusion they came to was that this wasn't truly doable any longer as too many scammers would use it to pop their pages to the front in an attempt to phish personal info. They recommend closing the page and then reopening it with a single function. – JLowther Jan 28 '20 at 03:14
  • Ya, I was about to say that. In that case, I will pass on some data to the local browser storage and then read it back when the new window opens. – Vik G Jan 28 '20 at 03:15
  • I'll be doing the same in the future. Best of luck. :) – JLowther Jan 28 '20 at 03:17
  • 1
    Use `GM_notification`. – wOxxOm Jan 28 '20 at 04:37
  • @wOxxOm that worked like a charm, thanks a ton – Vik G Jan 28 '20 at 05:42

1 Answers1

0

Looks like this cannot be done and the easiest option would be to write some data to the browser's local storage and then open a new window, fetch the data and display it.

Vik G
  • 539
  • 3
  • 8
  • 22