Made JavaScript URL manipulation more robust with URL and URLSearchParams.
Use the rich interface and native parsing provided by the browser rather than raw string manipulation. https://developer.mozilla.org/en-US/docs/Web/API/URL https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
This commit is contained in:
parent
ed6b14d459
commit
1e3ceb485e
|
@ -7,13 +7,9 @@
|
|||
|
||||
function showAdminPopup(triggeringLink, name_regexp, add_popup) {
|
||||
const name = triggeringLink.id.replace(name_regexp, '');
|
||||
let href = triggeringLink.href;
|
||||
const href = new URL(triggeringLink.href);
|
||||
if (add_popup) {
|
||||
if (href.includes('?')) {
|
||||
href += '&_popup=1';
|
||||
} else {
|
||||
href += '?_popup=1';
|
||||
}
|
||||
href.searchParams.set('_popup', 1);
|
||||
}
|
||||
const win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
|
||||
win.focus();
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
ready(function() {
|
||||
function handleClick(event) {
|
||||
event.preventDefault();
|
||||
if (window.location.search.includes('&_popup=1')) {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
if (params.has('_popup')) {
|
||||
window.close(); // Close the popup.
|
||||
} else {
|
||||
window.history.back(); // Otherwise, go back.
|
||||
|
|
Loading…
Reference in New Issue