jquery.fileDownload icon indicating copy to clipboard operation
jquery.fileDownload copied to clipboard

Need support base-url when using iframe to download

Open terrydai opened this issue 8 years ago • 1 comments

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

terrydai avatar Jun 06 '17 03:06 terrydai

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

johnculviner avatar Jun 14 '17 03:06 johnculviner