admin管理员组文章数量:1315359
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);
}
I want to add multiple params to url without reloading the page like:
- txt1
- txt2
- txt3
- link1
- link2
- link3
i want url : "..../search.php"
after click on txt2 i want url : "..../search.php#t_2"
after click on link2 i want url : "..../search.php#t_1&l_2"
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);
}
I want to add multiple params to url without reloading the page like:
- txt1
- txt2
- txt3
- link1
- link2
- link3
i want url : "..../search.php"
after click on txt2 i want url : "..../search.php#t_2"
after click on link2 i want url : "..../search.php#t_1&l_2"
Share Improve this question edited Mar 24, 2015 at 11:32 The Dark Knight 5,58513 gold badges58 silver badges104 bronze badges asked May 4, 2012 at 8:21 Manoj PatilManoj Patil 351 gold badge1 silver badge9 bronze badges 1- i want to add mutliple parameter in url like: – Manoj Patil Commented May 5, 2012 at 6:07
2 Answers
Reset to default 6You can only do this using history.pushState(state, title, url)
which is an HTML5 feature.
There is a new feature that aims to replace the use of location.hash
with a better solution: pushState
.
window.history.pushState(data, "Title", "/new-url");
More information: http://badassjs./post/840846392/location-hash-is-dead-long-live-html5-pushstate
本文标签: javascriptAppend parameter in url without reloading pageStack Overflow
版权声明:本文标题:javascript - Append parameter in url without reloading page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741975936a2408119.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论