diff --git a/datamodels/2.x/itop-portal-base/portal/public/js/portal_form_handler.js b/datamodels/2.x/itop-portal-base/portal/public/js/portal_form_handler.js index 3d6cf596e4..23d7375545 100644 --- a/datamodels/2.x/itop-portal-base/portal/public/js/portal_form_handler.js +++ b/datamodels/2.x/itop-portal-base/portal/public/js/portal_form_handler.js @@ -426,12 +426,34 @@ $(function() } else { - // Try to close the window - window.close(); + + if(window.history.length == 1) { + + // This window doesn't seem to be a modal, yet there is no history. Try to close the window. + window.close(); - // In some browser (eg. Firefox 70), window won't close if it has NOT been open by JS. In that case, we try to redirect to homepage as a fallback. - var sHomepageUrl = (this.options.base_url !== null) ? this.options.base_url : $('#sidebar .menu .brick_menu_item:first a').attr('href') - window.location.href = sHomepageUrl; + // In some browser (eg. Firefox 70), window won't close if it has NOT been open by JS. In that case, we try to redirect to homepage as a fallback. + var sHomepageUrl = (this.options.base_url !== null) ? this.options.base_url : $('#sidebar .menu .brick_menu_item:first a').attr('href') + + var regexPortal = new RegExp('(pages\\/exec\\.php)(.*?)(\\?exec_module=itop-portal-base&exec_page=index\\.php&portal_id=.*?)(&|$)'); + var aRegexMatch = window.location.href.match(regexPortal); + + if(aRegexMatch !== null) { + + sHomepageUrl += aRegexMatch[1] + aRegexMatch[3]; + + } + + window.location.href = sHomepageUrl; + + } + else { + + // Unless the previous page was for some reason an automatic redirection to the current one, this should work: + window.history.back(-1); + + } + } }, submit: function(oEvent)