From a Drupal JS app.
Last active
August 15, 2019 06:18
-
-
Save dotherightthing/bdc1d9e8b5c3d1187cdd to your computer and use it in GitHub Desktop.
[Reload page by stripping page from URL] #drupal #javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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