使用pushstate添加查询字符串 [英] Add query string using pushstate

查看:117
本文介绍了使用pushstate添加查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做类似下面的事情

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);
}

我的路径名正确,但是查询字符串为Nan.例如,我得到类似

I am getting pathname correct, but getting query string as Nan. For example I am getting result like

http://example.com/mypage/Nan

代替

http://example.com/page/?myNewUrlQuery=1

请告诉我是否可以使用pushstate方法在URL中添加查询字符串.如果是,那么任何可行的示例都将非常有帮助.

Please tell me is it possible to add query string in URL using pushstate method. If yes, any working example will be extremely helpful.

谢谢.

推荐答案

+ url

url变量之前,您有一个Unary plus运算符,可将其转换为数字.由于它不是包含数字的字符串,因此您会得到 Not A Number .删除+.

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

这篇关于使用pushstate添加查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆