0

I am passing a filepath for excel sheet download through encodeURI component and i am passing the encoded url to window.open() method in javascript but, what happens is a new tab is opening but it is not closing even after the file got downloaded. the encoded filepath is getting decoded in the view I am not good at javascript

the file path i am passing :

/royallondon/en-gb/royallondon-new/DownloadTool/GetDividendHistoryFile?modelString={%22GrsProjectId%22:%2228600023%22,%22ProjectName%22:%22royallondon%22,%22ToolId%22:18,%22LanguageId%22:%221%22,%22LanguageCode%22:%22en-gb%22,%22OverrideDocumentCountryCode%22:null,%22forSaleIn%22:%22%22,%22FSIexclCT%22:%22%22}&filtersString={%22TypeCode%22:%22FP:NQE8%22,%22FundName%22:%22RLPPC%20Enhanced%20Buy%20and%20Maintain%20Credit%20Pn%20Inc%22,%22BaseCurrency%22:%22%22,%22PriceType%22:%22%22,%22StartDate%22:null,%22EndDate%22:null}&sectionId=30608109

the encoded file path after passing the file path into encodeURIcomponent:

"/LoadDoc?FilePath=%2Froyallondon%2Fen-gb%2Froyallondon-new%2FDownloadTool%2FGetDividendHistoryFile%3FmodelString%3D%7B%22GrsProjectId%22%3A%2228600023%22%2C%22ProjectName%22%3A%22royallondon%22%2C%22ToolId%22%3A18%2C%22LanguageId%22%3A%221%22%2C%22LanguageCode%22%3A%22en-gb%22%2C%22OverrideDocumentCountryCode%22%3Anull%2C%22forSaleIn%22%3A%22%22%2C%22FSIexclCT%22%3A%22%22%7D%26filtersString%3D%7B%22TypeCode%22%3A%22FP%3ANQE8%22%2C%22FundName%22%3A%22RLPPC%2520Enhanced%2520Buy%2520and%2520Maintain%2520Credit%2520Pn%2520Inc%22%2C%22BaseCurrency%22%3A%22%22%2C%22PriceType%22%3A%22%22%2C%22StartDate%22%3Anull%2C%22EndDate%22%3Anull%7D%26sectionId%3D30608109&themeName=royallondon-new&projectName=royallondon"

the code used:

var absolutePath = '/' + GetLoader(loaderIdentifier) + '?FilePath=' + encodeURIComponent(filePath) + "&themeName=" + modelContents.Theme + "&projectName=" + modelContents.ProjectName;

if (!(eventObj) || !(eventObj.target) || !(eventObj.currentTarget) ||
    (eventObj.currentTarget.className != "fe-icon-chart"))
    window.open(absolutePath, (openWindowMethod == "" ? '_blank' : openWindowMethod));
else {
    window.open(absolutePath, (openWindowMethod == "" ? '_self' : openWindowMethod));
}

the code in view is:

if (window == window.top)
            maximizeWindow();

$(function () {
    var filePath = getParameterByName('@ViewData["FilePath"]');
    if (filePath) {
         window.location.replace(filePath);
    }
    $("#loaderIcon").removeClass("loading-indicator").addClass("loading-indicator");
});

function maximizeWindow() {
    window.moveTo(0, 0);
    if (document.all) {
        top.window.resizeTo(screen.availWidth, screen.availHeight);
    }
    else if (document.layers || document.getElementById) {
        if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth) {
            top.window.outerHeight = screen.availHeight;
            top.window.outerWidth = screen.availWidth;
        }
    }
}

function getParameterByName(filePath) {
    return decodeURIComponent(filePath.replace(/\+/g, ' '));
}
James Z
  • 12,209
  • 10
  • 24
  • 44
  • Possible duplicate of [Auto-closing a popup with a file to download](https://stackoverflow.com/questions/23638252/auto-closing-a-popup-with-a-file-to-download) – emerson.marini Apr 26 '19 at 12:33
  • I cannot use timeout option, if the file is bigger and i set less amount of time, the window will close even before the file gets downloaded. is there any other option to use other than window.location.replace to automatically close the child window once the download is completed?? – Vladimir21 Apr 29 '19 at 09:36

0 Answers0