Reputation: 4562
I was trying to pass a variable before reload in javascript. If I used the following code,
var myUrl = location.href;
if (myUrl.substring(myUrl.length-1) == "#")
{
myUrl = myUrl.substring(0, myUrl.length-1);
}
myUrl =myUrl+"&abc=Y&bdc=N";
location.href =myUrl;
location.reload();
This time I am not getting correct url.ie,I am not getting &abc=Y&bdc=N
in the URL. If I put the alert like this,
var myUrl = location.href;
if (myUrl.substring(myUrl.length-1) == "#")
{
myUrl = myUrl.substring(0, myUrl.length-1);
}
myUrl =myUrl+"&abc=Y&bdc=N";
location.href =myUrl;
alert(location.href);
location.reload();
Upvotes: 1
Views: 4246
Reputation: 372
Remove
location.href =myUrl;
location.reload();
Use only
window.location.href = window.location.href;
Upvotes: -1
Reputation: 3907
Remove
location.href =myUrl;
location.reload();
Use only
window.location =myUrl;
Upvotes: 3