Change iFrame src on ajax complete
Solution 1
An alternate approach that avoids both an iframe and the info bar is to simply not open the PDF automatically. In the call AJAX callback, create a regular link to the PDF file so the user can click on it directly. This should prevent IE from flagging the download.
Solution 2
You could try this if you don't want to use jQuery
document.getElementById("myframe").src=src;
try this wit jQuery
var iframe = $('#myframe');
$(iframe).attr('src', src)
In order to open a PDF try this
window.open(src);
will open the pdf in a new window...but the info bar cannot be avoided....
mentxugle
Updated on June 04, 2022Comments
-
mentxugle almost 2 years
using jQuery's $.ajax() I want to retrieve some information from the server, and then, based on that info, change the src attribute of an iframe.
Something like:
$.ajax( { url: "someUrl.aspx/getInfo", dataType: "json", data: "{'data':{'data1':'data1'}}", type: "post", contentType: "application/json; charset=utf-8", complete: function(data, stat) { if (stat == "success" ) { var src = JSON.parse(jsondata.responseText).d.src $('#myframe').attr("src",src); } } } );
The page I am trying to load is returning a PDF file, so the goal is to show the user the dialog to choose between downloading or opening that file. On IE7 and 8 the browser is showing the info bar with this message : "To help protect your security, Internet Explorer blocked this site from downloading files to your computer. Click here for options."
Changing the iframe's src attribute OUTSIDE the ajax call works fine and the dialog to choose between opening or saving the PDF is shown.
Any workarounds to avoid the info bar showing? Thanks in advance.