Javascript bring a tab to the front - javascript

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.

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.

Related

Сhecking data updates on the site using a chrome extension

I am trying to create a chrome extension, one of the functions of which will be to check for the appearance of new data on the site after clicking the start button in a pop-up window.
Our site has a table in which new data appears from time to time, we need to receive in chrome.storage only those data that appeared on the site after pressing the start button, and stop receiving after pressing the stop button.
Maybe someone knows some APIs for writing such functionality, or maybe some functions for it, I would be grateful for any advice?
you can use MutationObserver, but configure it carefully to watch only required nodes

How to change the text on the page refresh message pop-up?

I have a web page that gets refreshed, when something happens on any of its children pages. When it happens, the IE pop-up appears with the following message: "To display the webpage again, the web browser needs to resend the information you've previously submitted. If you were making a purchase, you should click Cancel to avoid a duplicate transaction. Otherwise, click Retry to display". See the image attached:
I'm ok with all that, but I was wondering if there's a way to change the actual text of the message, for example, removing the last sentence. I know this pop-up can't be tampered with, but perhaps there's a way to replace it with a custom made pop-up, serving the same function, but showing a different text. I assume first I would have to suppress the original message, then call a confirm box in a beforeupdate function, where clicking OK (for example) would resend the information submitted and Cancel would let you remain on the page without refreshing it. However, my Javascript and JQuery knowledge is a bit rusty and I'm not sure how to implement it properly. Any help is appreciated.
Thank you

Focusing browser tab when a value within the page reaches a specific number

I have a web page that refreshes constantly, where a span have a number that is changing (decreasing).
Is there a way using JS for example to automatically focus the browser tab containing the web page when that number reaches less than 10 so that the supervisor takes action before hitting 0 without knowing?
Thanks.
This is not possible.
There's two possible solutions.
Browser extension. This will give you a lot more leeway and control.
And this has become a lot more popular is to change the favicon on the page to another one that looks like an alert. And changing the title too. Playing a sound is another cue to the user that something has happened.
Hope this helps!
Depending on the browser and the user’s settings, alert might take the user to the tab that opened the alert. In other browsers alert might only change the tab icon to stand out.
Firefox gives the user the option to enable this behavior with a “Allow dialogs from example.com to take you to their tab” checkbox, unchecked by default:
Chrome doesn’t give the user any such option, but does mark the tab with an orange indicator:
You can test your browser’s behavior by running this snippet and then switching to another tab:
setTimeout(function() {
alert('this is a delayed alert');
}, 3*1000);

Required fields not met when closing window

I'm looking for the best way to go about "forcing" the user to fill a textarea.
For my work we have a system that keeps track of time spent on a particular "task". Some tasks are required to have a comment while others are optional. At the top of the page there is a timer, a textarea for the comments and a list of different tasks.
So far I have it so when the user tries to stop the timer, it won't stop until the comment is written (if it is required). When the paged is closed while the timer is running, an onbeforeunload function sends an alert warning that the comments aren't filled out and then the "Are you sure you want to leave?" warning pops up.
As far as I can tell there is no way to prevent the user from completely exiting the page. The idea we had was when the user closes the window, have another simple page open that just has a textarea and an instruction telling the user to write a comment. I'm pretty new to JavaScript and web development so I'm not entirely sure the best way to go about this.
Put that text area in a popup or iframe or modal window where you can control its closing.
On these window.close you can call the functions to validate the text area is filled or not.
Am not sure you can put that in a popup or not .but thats the only good way i can think of !!
There is no way to prevent the user from leaving a page.
Built in pop up blockers will also block the system from opening up popup windows onunload. Only way to allow onunload popups is if your system admins can update every browser to add an exception to the browser security settings.
It is impossible to make a web application act like a client application.

Alternatives to disabling / disable back button in firefox and IE

Our application forbids going back for several reasons.
Basically because that's just how our application works (JSF with facelets as GUI)
You always have to enter on the welcome site, once you chose an application-flow you can only leave / abort when you tell the application (e.g. press a button). If you just browse away e.g. enter "example.com" in the address bar the state of your flow gets saved and once you relogin, you can resume the work. Going back is only possible when it was specifically designed like this with a 'back' submit - button.
Of course users keep pressing the 'back' button (i would do so as well) and they keep getting 'error: session out of synch'. This is a learning process and a couple years ago we just disabled the back-button to make things clear. Sadly this is no longer supported.
So instead of teaching the user the hard way and forcing him to relogin, are there some good alternatives I'm missing?
i found this link which should offer 3 methods to disable the back button - but in reality it just further confirms the fact that it is impossible to do it in a semi-nice way.
when the user tries to go to a previous page you can redirect him to the page he should be at in other words catch the "out of sync" and redirect him
You might find a workable solution here How do I insert an entry into browsing history via JavaScript
by inserting an extra step into the browser's history (perhaps a link to the current page with query string parameters that result in a nice big red box message to the user), or you could try attaching an event handler to the OnBeforeUnload event so the user gets a confirmation dialog when trying to leave the page (you'd want to remove the handler when the submit button was clicked).

Categories