IE iframe download causing security warning
My application takes AJAX requests and responds with a URL to a download location on my website for the file they're requesting. Then the Javascript AJAX method for success of the response, dynamically creates an iframe on the page with the src set to the download location, to开发者_JS百科 allow the file dialog to display so the user can download the file. The problem is IE displays the following security warning:
http://avnhelp.com/default_files/image004.jpg
The main reason this is a problem is because, when they click accept, it refreshes the page and the file download is lost (I'm assuming this is because it's in an iframe created dynamically).
I need a way to either:
disable this security dialog prompt
prompt the user when they visit the site to accept any future file downloads.
fix the fact that upon refresh (from accepting) the file download is lost.
Here is my iframe code:
function create_iframe(url) {
frame = document.createElement('IFRAME');
frame.setAttribute('src', url);
frame.style.display = 'none';
document.body.appendChild(frame);
}
If someone could help me with this, that'd be great! Thanks.
You can't disable the security warning. The browser will act like that whenever a file attachment shows up in an HTTP response that's not related to an HTTP request made from a user-initiated event ("click" or form submit). You're getting the warning because you're making the HTTP request from the ajax response event handler, and the browser simply does not like that.
The only way to make the setup work is to make sure that you start the HTTP request from a "click" handler, or the "submit" handler for a form (or by having the actual form submit result in the file response).
精彩评论