Skip to content

Instantly share code, notes, and snippets.

@keeprock
Created March 3, 2015 11:59
Show Gist options
  • Save keeprock/0239c578c68000d3a6ca to your computer and use it in GitHub Desktop.
Save keeprock/0239c578c68000d3a6ca to your computer and use it in GitHub Desktop.
Using History.API to display url in ajax loaded content
function custom() {
drupal_add_js(drupal_get_path('module', 'CURRENT_MODULE') . '/CURRENT_MODULE_proto.js');
$path = 'YOUR_PATH/' . $nid;
if ($alias = drupal_lookup_path('alias', $path)) {
$url = $alias;
} else {
$url = $path;
}
$commands[] = array(
'command' => 'CUSTOM_history',
'url' => '/' . $url
);
}
(function($) {
Drupal.ajax.prototype.commands.CUSTOM_history = function(ajax, response, status) {
history.pushState(null, null, response.url);
}
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment