In my Drupal site, I need to redirect the user to a certain page, and then have som javascript code execute once the page is loaded (in order to add a modal dialog on top of the page). After doing some reading, I tried this in my module file:
drupal_add_js(drupal_get_path('module', 'mymodule') . '/scripts.js', 'module');
drupal_goto('path/to/redirect');
And then in my javascript file (scripts.js):
Drupal.behaviors.mymodule_behaviour = function (context)
{
// do some fancy stuff
};
This doesn’t work, because the javascript is removed from the page when drupal_goto is run. Is there a way to preserve the javascript and make sure that it is run once the page is loaded?
Thank you in advance.
You’ll need to include
drupal_add_js(drupal_get_path('module', 'mymodule') . '/scripts.js', 'module');on the page that you’re redirecting to, not the page you’re redirecting from.