javascript 将查询参数附加到URL

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 将查询参数附加到URL相关的知识,希望对你有一定的参考价值。

// append custom query parameter
(function appendQueryParameter() {
  if (history.pushState) {
    var 
    queryParameter = $("#append-query-parameter").data("query-parameter");
    if (queryParameter !== undefined && queryParameter !== null && queryParameter !== ""){
	    var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?' + queryParameter;
    	window.history.pushState({path:newurl},'',newurl);
  	}
  }
})();

以上是关于javascript 将查询参数附加到URL的主要内容,如果未能解决你的问题,请参考以下文章