I am trying to close the current windows brower and open a new one. Currently, it opens a new window on each click which is not correct.
Not sure where am I doing wrong in this?
Can someone point me right direction?
<div id="oWrapper" style="display: none;">
<div id="oIn"></div>
</div>
$(document).ready(function () {
var isIE = false || !!document.documentMode;
if (isIE) {
var tURL = 'microsoft-edge:' + '@Url'.replace(/amp;/g, '');
var openE = document.querySelector('#oIn');
openE.href = 'microsoft-edge:' + document.URL;
var oWrapper = document.querySelector('#oWrapper');
oWrapper.style.display = 'block';
window.location.replace(tURL);
}
else {
var params = [
'height=' + screen.height,
'width=' + screen.width,
'scrollbars=yes',
'resizable=yes',
'location=no'
].join(',');
var Obj;
function ModalPopUp() {
Obj = window.open('@Url'.replace(/amp;/g, ''), "_blank", params);
Obj.moveTo(0, 0);
Obj.focus();
LoadModal();
}
function LoadModal() {
var Div = document.getElementById("oIn");
Div.style.display = "block";
}
function OnUnload() {
if (false == Obj.closed) {
Obj.close();
}
}
window.onunload = OnUnload;
ModalPop();
}
});
>Solution :
It seems like you only try to Obj.close upon window.onunload, instead of before a new modal is opened.
Try:
function ModalPopUp() {
if (Obj) Obj.close(); // close existing modal if it exists
Obj = window.open('@Url'.replace(/amp;/g, ''), "_blank", params);
Obj.moveTo(0, 0);
Obj.focus();
LoadModal();
}