Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript strong type for urls like window.location

Tags:

javascript

Using plain JS, I would like to get the current window.location, modify some of its parts and stringify the result - without changing the current location.

Pseudocode:

var oauth_redirect_uri = window.location.deep_clone();
oauth_redirect_uri.hash = "#OAuthCallback/EmailProvider";
var oauth_parameters = {
    redirect_uri: oauth_redirect_uri.toString()
};

What code would I have to use instead of the "deep_clone" function?

like image 444
Alexander Avatar asked Jun 17 '26 17:06

Alexander


1 Answers

Try new URL()

var oauth_redirect_uri = new URL(window.location);
oauth_redirect_uri.hash = "#OAuthCallback/EmailProvider";
var oauth_parameters = {
    redirect_uri: oauth_redirect_uri.toString()
}

console.log('window.location', window.location.toString())
console.log('oauth_parameters', oauth_parameters)

See https://developer.mozilla.org/en-US/docs/Web/API/URL/URL

like image 123
Phil Avatar answered Jun 19 '26 06:06

Phil