IMUXIxD
IMUXIxD

Reputation: 1227

Send window.location to a variable, which is a URL in string form

I am trying to send window.location to a variable, but my method doesn't seem to be working.

I have one variable that is the query called query and another caller firstPart. I concatenate them and am trying to sent window to that concatenated URL, but it doesn't seem to work.

Here is what I have so far:

var query = "hello";
var firstPart = "http://google.com/?=";
window.location.assign(firstPart + query);

Upvotes: 2

Views: 6314

Answers (2)

Ryan
Ryan

Reputation: 5682

var query = "hello";
var firstPart = "http://google.com/?=";
window.location.href = firstPart + query;

More on window location here https://developer.mozilla.org/en-US/docs/DOM/window.location

Upvotes: 0

Do it like this:

window.location.href = firstPart + query;

Upvotes: 2

Related Questions