Add query string using pushstate

人走茶凉 提交于 2019-12-24 16:31:09

问题


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.


回答1:


+ 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 +.



来源:https://stackoverflow.com/questions/24465030/add-query-string-using-pushstate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!