Error message

Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /home1/tylerfra/public_html/includes/common.inc).

Drupal URL Arguments in Javascript

Category: 

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:

http://www.tylerfrankenstein.com/chicken/burrito/combo

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.

Comments

It is very helpful.
Thanks

For Drupal 7 (this didn't work, but...) there is a plugin available here: https://gist.github.com/3078482