Currently, my approach involves using Javascript and Ajax to retrieve data and display it in a new window. I am encountering an issue where I am trying to close the window in the OpenFileWindow() function before opening a new one, but I am facing a permission denied error for all properties and methods related to the window object.
I suspect that the problem is related to scoping with the Ajax call, as there are no issues when I open the window before making the XMLHttpRequest.
I have conducted extensive research but am unsure of how to proceed. Does anyone have any suggestions or insights? Thank you.
opened
var newWin = null;
function View_onClick(propId, url) {
var param = "propId=" + propId;
param += "&filename=" + url;
var xhr = new XMLHttpRequest();
xhr.open("POST", "GetActivityFileName.ashx", false);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
if (xhr.responseText == "") {
alert("Sorry unable to find file.");
return false;
}
else {
OpenFileWindow(xhr.responseText);
return false;
}
}
}
};
xhr.send(param);
return false;
}
function OpenFileWindow(fileUrl) {
if(newWin != null)
newWin.close();
newWin = window.open(fileUrl);
newWin.focus();
}