Reputation: 49823
i need a function to replace url params like this
users/?id=9&op=0?iu=0&t=9
to
users/?id=9&op=0&iu=0&t=9
can someone show me some piece of code to do that?
Upvotes: 1
Views: 123
Reputation: 15024
Try this:
function fixurl(url) {
var urlarray = url.split('?');
var parsed = urlarray[0] + '?' + urlarray[1] + '&' + urlarray[2];
return parsed;
}
It turns users/?id=9&op=0?iu=0&t=9
into users/?id=9&op=0&iu=0&t=9
.
And users.html/?id=9&op=0?iu=0&t=9
into users.html/?id=9&op=0&iu=0&t=9
.
Upvotes: 0
Reputation: 11352
function fixURL(url){
return url.replace(/\?/g,'&').replace('&','?');
}
fixURL('users.html?id=9&op=0?iu=0&t=9');
Upvotes: 1