Skip to content

Instantly share code, notes, and snippets.

@dotherightthing
Last active August 15, 2019 06:18
Show Gist options
  • Save dotherightthing/bdc1d9e8b5c3d1187cdd to your computer and use it in GitHub Desktop.
Save dotherightthing/bdc1d9e8b5c3d1187cdd to your computer and use it in GitHub Desktop.
[Reload page by stripping page from URL] #drupal #javascript

Reload page by stripping page from URL

From a Drupal JS app.

var path = window.location.pathname, // /foo/bar/baz
current_page = path.substring( path.lastIndexOf('/') ), // get everything after the last slash
current_page_reloaded = path.replace(current_page, '/'); // strip everything after the last slash
// reload /foo/bar rather than /foo/bar/baz
window.location.href = window.location.origin + current_page_reloaded;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment