Skip to content

Commit 11e0246

Browse files
committed
Refactor getParameterByName function to use URL interface
1 parent ee0893f commit 11e0246

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

js/utils.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
function getParameterByName(name = '', url = '') {
22
if (!url) url = window.location.href;
3-
name = name.replace(/[[\]]/g, '\\$&');
4-
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
5-
results = regex.exec(url);
6-
if (!results) return null;
7-
if (!results[2]) return '';
8-
return decodeURIComponent(results[2].replace(/\+/g, ' '));
3+
4+
const urlObject = new URL(window.location.href);
5+
return urlObject.searchParams.get(name);
96
}
107

118
export default getParameterByName;

0 commit comments

Comments
 (0)