Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using javascript navigate to a page and also send querystring?

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?

like image 283
mustafa mukadam Avatar asked Sep 13 '25 07:09

mustafa mukadam


1 Answers

Have 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.com/?test=blah&foo=bar';
window.location.href = 'http://google.com/?test=blah&foo=bar';
like image 178
mswieboda Avatar answered Sep 14 '25 21:09

mswieboda