I want to navigate from page1.html to page2.html and at the same time adding querystring in URL using javascript.
I tried:
window.location.href = 'page2.html?uname=mustafa';
It does navigate to page2.html but "?uname=mustafa" is not added in URL. So am unable to parse querystring on page2. How can I achieve it?
I want to navigate from page1.html to page2.html and at the same time adding querystring in URL using javascript.
I tried:
window.location.href = 'page2.html?uname=mustafa';
It does navigate to page2.html but "?uname=mustafa" is not added in URL. So am unable to parse querystring on page2. How can I achieve it?
Share Improve this question asked Jan 26, 2015 at 17:30 mustafa mukadammustafa mukadam 731 silver badge8 bronze badges 8- Basically, I want to send data between html pages without using server-side scripting. – mustafa mukadam Commented Jan 26, 2015 at 17:32
- I just tried your code on a chrome console and it did what you are asking for – bitoiu Commented Jan 26, 2015 at 17:35
- 1 what is your serverside set up? maybe you are using a cms or some sytem thats stripping the query string? – atmd Commented Jan 26, 2015 at 17:36
-
1
try
window.location = 'page2.html?uname=mustafa';
– charlietfl Commented Jan 26, 2015 at 17:42 - 2 It turns out there is some error in other part of code. Above solution worked! – mustafa mukadam Commented Jan 26, 2015 at 18:09
3 Answers
Reset to default 3Have you tried using just
window.location = 'page2.html?uname=mustafa';
instead of using .href
? This should preserve the querystring.
Worked for me in Chrome and FF with .href
just fine, but I used absolute URLs:
window.location = 'http://google./?test=blah&foo=bar';
window.location.href = 'http://google./?test=blah&foo=bar';
I have ran into this problem before as well. I used location.href
with an absolute URL and a parameters array like the follow:
var params = [];
params.push("uname=" +mustafa);
location.href = "http://localhost:port/page2.html?" + params.join("&");
try this
window.location = `addUser.html?userId=${userId}`;
here userId
is a parameter and ${userId}
is variable value