问题描述
我使用以下code追加参数,以URL。这是工作正常,但当参数的URL追加,页面重新加载得到。我想无需重新加载页面使用此功能。
I am using following code to append param to url. This is working fine but when parameter is appended in url, page is getting reloaded. I want to use this functionality without reloading the page .
function insertParam(key, value)
{
key = escape(key); value = escape(value);
var kvp = document.location.search.substr(1).split('&');
var i=kvp.length; var x; while(i--)
{
x = kvp[i].split('=');
if (x[0]==key)
{
x[1] = value;
kvp[i] = x.join('=');
alert('sdfadsf');
break;
}
}
if(i<0) {kvp[kvp.length] = [key,value].join('=');}
//this will reload the page, it's likely better to store this until finished
document.location.search = kvp.join('&');
//alert(document.location.href);
}
我要添加多个PARAMS给url无需重新加载页面,如:
}
I want to add multiple params to url without reloading the page like:
- TXT1
- TXT2
- txt3
- 链接1
- 链接2
- LINK3
我想网址:...... / search.php中
i want url : "..../search.php"
点击TXT2后
我想网址:...... / search.php中#T_2
after click on txt2i want url : "..../search.php#t_2"
点击链接2后
我想网址:...... / search.php中#T_1&安培; L_2
after click on link2i want url : "..../search.php#t_1&l_2"
推荐答案
您只能做到这一点使用<$c$c>history.pushState(state,标题,URL) 这是一个HTML5的功能。
You can only do this using history.pushState(state, title, url)
which is an HTML5 feature.
这篇关于在追加URL参数而不需要刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!