Question

I'm working on a module and am trying to add some javascript to the next page a user sees after logging in or out. Calling drupal_add_js() on hook_user (op == login) doesn't seem to work; I'm assuming this is because drupal_goto is called after the login is completed and a fresh page request is initiated.

I've considered using hook_user to set session variables which I can then respond to on the next page load but that seems somewhat fragile. Any suggestions?

Was it helpful?

Solution

If you want something to be carried over to a new page you only have a few options:

  • Alter the url.
  • Store in the database.
  • Store in session.

Altering the url, would probably be quite hard and messy. Storing in the session or database is basically the same thing. So you would probably want to use the Drupal session system instead of making your own.

You could add something in the session and then in hook_init check for it and if it's there add the js and delete it from the session.

I don't think you will find a much better solution, though it would be nice if there were.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top