传递编码的URL时Window.Open()不起作用

时间:2019-04-26 12:18:58

标签: javascript encodeuricomponent

我正在通过encodeURI组件传递用于Excel工作表下载的文件路径,并且正在将编码的url传递给javascript中的window.open()方法,但是发生的是一个新标签页正在打开,但即使在文件打开后也没有关闭已下载。编码的文件路径在视图中被解码 我不擅长javascript

我要传递的文件路径:

/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

将文件路径传递到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"

使用的代码:

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));
}

视图中的代码为:

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, ' '));
}

0 个答案:

没有答案