I am doing something like below
if(history.pushState)
{
var stateObject = { dummy: true };
var url = window.location.protocol
+ "//"
+ window.location.host
+ window.location.pathname
+ '?myNewUrlQuery=1';
history.pushState(stateObject, jQuery(document).find('title').text(), + url);
}
I am getting pathname correct, but getting query string as Nan. For example I am getting result like
http://example.com/mypage/Nan
Instead of
http://example.com/page/?myNewUrlQuery=1
Please tell me is it possible to add query string in URL using pushstate method. If yes, any working example will be extremely helpful.
Thanks in advance.
+ url
You have a Unary plus operator before the url
variable that converts it to a number. Since it isn't a string containing a number you get Not A Number instead. Remove the +
.