Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need support base-url when using iframe to download #149

Open
terrydai opened this issue Jun 6, 2017 · 1 comment
Open

Need support base-url when using iframe to download #149

terrydai opened this issue Jun 6, 2017 · 1 comment

Comments

@terrydai
Copy link

terrydai commented Jun 6, 2017

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');
@johnculviner
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants