Trigger ajax action by url or link I currently have a page which has a block with taxonomy terms displayed.  Each link has been made to work with ajax to display information below if clicked, generated in a module callback.

What I am trying to acheive is also have this work if linked to.  So for example my page URL is currently http://localhost/events/building01 
If someone was to visit http://localhost/events/building01/printer then the information for printer would be displayed under the taxonomy term as it would if someone had clicked on the term.

My ajax links are currently setup like:

function building_block_menu() 
{
  $items['events/%/%/ajax'] = array(
  'title' =&gt; 'ajax call',
  'page arguments' =&gt; array(1, 2),
  'page callback' =&gt; '_event_ajax_callback',
  'access arguments' =&gt; array('access content'),
  'type' =&gt; MENU_CALLBACK,
  );
  $items['events/%/%/nojs'] = array(
  'title' =&gt; 'nojs call',
  'page arguments' =&gt; array(1, 2),
  'page callback' =&gt; '_event_nojs_callback',
  'access arguments' =&gt; array('access content'),
  'type' =&gt; MENU_CALLBACK,
  );
  return $items;
}
function _event_ajax_callback($building, $type)
{
  $markup = $building . ' - ' . $type;
  $ajax_commands = array();
  $ajax_commands[] = ajax_command_html('#ajax-target', $markup);
  ajax_deliver(array('#type' =&gt; 'ajax', '#commands' =&gt; $ajax_commands));
}
function _event_nojs_callback() 
{
  return "no js to be built";
}


And called from links built like:

$output .= l($term-&gt;name, 'events/$building/'.$term-&gt;tid.'/nojs', array(
            'attributes' =&gt; array('id' =&gt; 'building-term-'.$term-&gt;tid, 'class' =&gt; 'use-ajax')
            ));
The easiest option would be to add an ID to each link like link_printer and then use jQuery to parse the url, get the last fragment, and click any links that match.

var splitURL = window.location.href.split('/');
var link_id = '#link_' + splitURL[splitURL.length - 1];
if ($(link_id).length &gt; 0) document.querySelector(link_id).click();