Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By tm0032938 on
I have a site which contains many links. Now I want to achieve the
following:-
- Authenticate user in my site opens a in new tab of browser.
- Authenticate User log out from one of the tab.
- If user select link on the page that is still opened in tab 2 then it should redirect to login page.
Please provide your valuable input to achieve this functionality.
Comments
You can implement hook_page
You can implement hook_page_alter (which is called on every page load), and if the user is not logged in, use drupal_goto() to redirect to the front page.
I have implemented your
I have implemented your suggestion and it worked like charm.
However I have two situations in this scenario where I need such advises:-
I don't have an answer for
I don't have an answer for your first scenario, I'd have to sit down and play with it for a while, and I don't have the time to do that at the moment.
For your second scenario, you can append the 'destination' query to the URL that will redirect the user back to the page they were on. You can do that like this, still in hook_page_alter():
Again thanks for your
Again thanks for your suggestion regarding 2nd problem. It is working fine now.
Regarding first one, I tried to do following but it is not working:-
This is not invoking the JS code when page is loaded. Is my approach correct?
I have no idea if your idea
That will not work because the JS is added, but then you are redirecting to another page, which will not have that JS. You would need to add that on the page the user is redirected to. I don't know if that will work though. Probably better to start a new thread.
Also, google 'Managing JavaScript in Drupal 7', as you are not using the D7 JavaScript APIs.