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
Jafar Taghipour (not verified)
Sat, 02/18/2012 - 00:50
Permalink
It is very helpful. Thanks
It is very helpful.
Thanks
Anonymous (not verified)
Mon, 07/09/2012 - 15:48
Permalink
For Drupal 7 (this didn't
For Drupal 7 (this didn't work, but...) there is a plugin available here: https://gist.github.com/3078482