Need support base-url when using iframe to download
When the parent framework has a base tag and I pass a relative url to make a post download, but the resolved url is not right . Can jquery.fileDownload support this feature ?
index.html
<base href="/award/">
app.js
file-download(url="export/awards")
When I browse http://localhost/award/abc/def , the download url resolved to http://localhost/award/abc/def/export/awards.
Then I found that jquery.fileDownload used iframe to make a post request in iframe , but the iframe did not inherit the base url . Here is my solution:
//use base url
var baseTag = ''
var baseUrl = $('base').attr('href')
if(baseUrl){
baseTag = "<base href='" + baseUrl + "'>"
}
formDoc.write("<html><head>"+ baseTag +"</head><body><form method='" + settings.httpMethod + "' action='" + fileUrl + "'>" + formInnerHtml + "</form>" + settings.popupWindowTitle + "</body></html>");
// formDoc.write("<html><head></head><body><form method='" + settings.httpMethod + "' action='" + fileUrl + "'>" + formInnerHtml + "</form>" + settings.popupWindowTitle + "</body></html>");
$form = $(formDoc).find('form');
Hey there, thats a cool idea. If you'd like to send me a pull request doing this would be happy to merge it. It should not be the default behavior as it would break other people currently using the library but some sort of a boolean "inheritBasePath". you could also accomplish that pretty readily just looking at window.location and passing it into filedownload (Since you have control over the path). cheers, John