block current window for n seconds with JS - javascript

I am developping a web app using backboneJs and nodeJS, I want to oblige the user to not close this current window for 10 seconds, after 10 seconds he can do whatever he likes. Is it possible with JS?

The window settings are controlled by your browser (Chrome/Firefox/Safari etc.). So anything that lies beyond what appears on the website screen is not in our control.
Incase you want to ensure the user reads a particular message for a given timestamp, I suggest using popovers or a custom landing page should be of good use.

Related

Rails 7 - Opening initial window and closing after n seconds

First, I will start out saying I understand the concept that a window not opened by you with JavaScript cannot be closed by you using window.close(). What I am wondering is if in Rails (Rails-7 for me), is there a way, perhaps using an initialize script, to open the default window using window.open(). What I am trying to accomplish is, a user scans a QR code that directs to another path in my routes, it will display a message and screen colour change for 10 seconds. At this point, I want that tab plus the initial opening default tab to close, and the application is then closed. The second tab is no problem but I need to be able to close the beginning tab as well, otherwise, the user will end up with a new tab for every QR they scan, which could result in hundreds in the course of a day. Thanks in advance for any input.

Chrome Window X event with Locking [duplicate]

This question already has answers here:
Run JavaScript code on window close or page refresh?
(8 answers)
Closed 1 year ago.
I have a site I'm building where a user clicks a row from a datagrid and it opens a new Chrome window with a form filled with data from the row. I only want one user editing the data at a time so if another user gets in, the screen is read-only. I do this by setting a LockUserID and LockDate on the row after a user enters. The minute the first user (lockuser) saves the data it will close the window and null out the LockUserID and LockDate so then next person can get in.
My problem is if a user clicks the chrome x button I don't know that the user left therefore the LockUserID and LockDate still have a value on the row and anyone that gets in afterward will have a read only view.
I have tried using before unload but this almost feels like a hack considering beforeunload is used for refreshing and other events.
Does anyone have any better suggestions with locking?
Maybe you can send a regular AJAX request to the server. Let's say every 30 seconds. The server saves the time. When a new user tries to open the side you can check if the interval is bigger between the last incoming request and the current time than the 40 seconds and if so unlock the site.
Not the best solution i think but it should work
Or the better solution: Run JavaScript code on window close or page refresh?

Understanding anonymous user in Drupal 7 form using Jquery

I have site which contains many links. User can open links in new window. User can log out from one window. If they do so and click on the other window of my site then I want to give an alert to the user saying that "Please login to continue". My questions are:-
Is this possible in Drupal 7?
Is there any extra module to support this.
If there is no contributed module available for this then my idea is to register a click event on the page(document) inside JQuery which will always check if user is authenticated or not. I want to know that which function in Drupal will help me in understanding authenticated user of site in JQuery.
Please share if any other option available to achieve this goal.
This is not an easy task, but I am going to explain how I would do so (without too many details):
Create a web service which receives a cookie and returns whether it represents a live session or not.
Use the visibility change javascript event to detect when a user leaves the browser or comes back in. When you notice the user has come back to the browser, perform an AJAX call to the server you set up in step one. You should provide the cookie stored in the browser, and expect a boolean answer.
Depending on the response given by the server, display a modal dialog with Javascript showing a login form orwhatever you consider necessary.
Note: This method will only work if the user is using a browser supporting visibility change events, and can be bypassed disabling Javascript code execution. In addition, the user will still be able to see the content if the browser is not the focused window (for example, there are two opened windows, each of them covering one half of the screen. The event will not fire until the focus comes back to the "forbidden" window).

Webpage redirection time

I want to calculate time consumed in redirecting from 1 webpage to another webpage.
For Example:
1) I am using Facebook in Google Chrome browser.
I have shared 1 link on my Facebook profile like below:
http://www.webdeveloper.com/
(It's not only Facebook. It can be any domain having link to another domain).
2) When I click on this link from my Facebook profile, then this website will open in new tab.
3) I want to calculate time difference in miliseconds or microseconds between below two events:
First Event: Time of clicking link "http://www.webdeveloper.com/" from my Facebook profile.
Second Event: Time of completely loading webpage of "http://www.webdeveloper.com/".
Thank you in advance.
Unless you load the linked page yourself into a frame or with xmlhhtp request, your facebook page does not have control of another page. In other words, as soon as the user clicks the link you have no control and it runs separately. If you use a frame or load the page ajax style with javascript into an object, it's not going to give you the same kind of timing. So this is basically a pointless excercise as you can't do it. You could potentially setup your own browser with whatever analyzer so it will give you timings but you can't set up any code that would time it for visitors, for the aforementioned reason. If it was possible to do such things then this code could also manipulate the linked to page and take over it. With such lax security you couldn't trust any link you click.

trigger jQuery code after 10 min on in-activity

What would be the best way to monitor activity of a user on the page? I am developing a CMS system and using this as a security feature, if user is inactive for set amount of minutes then jQuery would trigger a function which would trigger whole page overlay and load in login script having to force the user to re-enter the password in-order to reopen the page or else after so many failed attempts PHP would force the user to logout script and destroy entire session.
So here how it would go
If no activity after 5min
jQuery(checks user activity every 5min) -> loop <- jQuery(if no activity after 5min) -> function(trigger overlay + authorization script via AJAX)
If there is activity
jQuery(checks user activity every 5min) -> loop <- jQuery(if active go back to loop)
So ye this is about it, thanks in advance.
Activity Definition for this script: Movement of mouse or input(keyboard) of text into text fields or clicking elements.
You can use jQuery's Idle Timer plugin.
As Justin says, jQuery does have an idle timer plugin. However, this method is not going to be sufficient alone unless your idle timer also destroys login cookies - your overlay can easily be circumvented by an array of browser plugins, or even (depending on how your application is built) GET parameters.
Reloading the page would even circumvent this "security" unless you log the user out.

Categories

Resources