Error message

The spam filter installed on this site is currently unavailable. Per site policy, we are unable to accept new submissions until that problem is resolved. Please try resubmitting the form in a couple of minutes.

Drupal URL Arguments in Javascript


Sometimes a prerequisite to getting a burrito for lunch involves using Drupal URL arguments in Javascript. So for example, say you had a URL like this:

You can add code like this to your module:

function my_module_init () {
  drupal_add_js(array('arg' => arg()),'setting');

And finally you can use code like this in Javascript to use the Drupal URL arguments:

var drupal_arg0 = Drupal.settings.arg[0];
var drupal_arg1 = Drupal.settings.arg[1];
var drupal_arg2 = Drupal.settings.arg[2];

alert(drupal_arg0); // alert chicken
alert(drupal_arg1); // alert burrito
alert(drupal_arg2); // alert combo

There you have it, access to your Drupal URL arguments in Javascript. Now go get something to eat and get back to writing code... or else.


It is very helpful.

For Drupal 7 (this didn't work, but...) there is a plugin available here:

Add new comment