I am trying to show a download pop up to the user which is an ajax call giving text/csv formatted response.
The issue: it's working well in Firefox but not in Chrome, where it's opening a new tab. This is definitely unintended, and I would prefer it didn't happen. Any ideas on what I could change...?
function x() {
var obj = jQuery("input:checked").map(function()
{
return jQuery(this).parents('tr').attr('id');
});
var result = null;
var arr = jQuery.makeArray(obj);
var data = arr.join(',');
$.ajax({
url : '<%= url_for :controller => "liges", :action => "export_to_csv" %>',
type : 'POST',
data : {data:data},
dataType : 'string',
async: false,
success : function(response) {
window.open('data:text/csv;charset=utf-8,'+escape(response));
}
});
};
Try this:
window.open("","","width=400,height=150");
By the way chrome will block popup windows on page, until you give him access.
You need to pass _blank
as another parameter:
From MDN :
To open a new window on every call of
window.open()
, use the special value_blank
forstrWindowName
.
Example:
window.open('data:text/csv;charset=utf-8,'+escape(response), '_blank');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.