2

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.

simple user
  • 349
  • 3
  • 22
  • 44
  • I do not know if I get the point of what you are trying to do. If a user opens two windows, namely A and B and logs out from window A, window B will not be notified. The user will still be able to see the content, but will not be able to keep navigating through the page (in the next request the server will detect the session is no longer valid). – Bustikiller Nov 01 '15 at 17:37
  • If windows B still opened here and user click on any button/link in web page then my idea is to show an alert to user "Please Log In to Continue" before processing the form to server. Any views on this? – simple user Nov 02 '15 at 03:18

1 Answers1

0

This is not an easy task, but I am going to explain how I would do so (without too many details):

  1. Create a web service which receives a cookie and returns whether it represents a live session or not.
  2. 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.
  3. 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).

Community
  • 1
  • 1
Bustikiller
  • 2,423
  • 2
  • 16
  • 34