Skip to content

Instantly share code, notes, and snippets.

@mnutt
Last active April 29, 2020 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnutt/ea88907b74b0e818eb62f57addfd6b6e to your computer and use it in GitHub Desktop.
Save mnutt/ea88907b74b0e818eb62f57addfd6b6e to your computer and use it in GitHub Desktop.
function relativeHash(newUrl);
const currentUrl = new URL("http://somesite.com/index.html#/page/a"); // or just document.location
const newPath = new URL("../blog/b", `http://example.com${currentUrl.hash.slice(1)}`).pathname;
currentUrl.hash = `#${newPath}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment