Reputation: 6597
I am trying to redirect to a URL path that contains a query parameter called next
, which is itself a URL path that contains a fragment identifier. Here is the JavaScript code I tried:
window.location.href = "/gauth?next=" + window.location.pathname + "#onload=exportToDrive"
Just to make myself clear, the #onload=exportToDrive
should belong to the next
URL path (not the URL that the browser is redirecting to). How can I specify that information to the browser so that it will handle this situation correctly?
Upvotes: 0
Views: 877
Reputation: 203359
You should always encode URL parameter values properly, using a function like encodeURIComponent
:
window.location.href = "/gauth?next=" + encodeURIComponent(window.location.pathname + "#onload=exportToDrive");
This will ensure that any fragment identifiers (but also query string parameters) won't apply to /gauth
.
Upvotes: 1