-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.js
More file actions
28 lines (21 loc) · 834 Bytes
/
utils.js
File metadata and controls
28 lines (21 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
updateQueryStringParameter = function(key, value) {
if (!value) value='';
value = encodeURIComponent(value);
var uri = document.location.href;
var re = new RegExp("([?|&])" + key + "=.*?(&|$)", "i");
separator = uri.indexOf('?') !== -1 ? "&" : "?";
var res;
if (uri.match(re)) {
res = uri.replace(re, '$1' + key + "=" + value + '$2');
}
else {
res = uri + separator + key + "=" + value;
}
window.history.replaceState({},"", res); // change replaceState to pushState if you want a new history entry
}
getParameterByName = function(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}