My post method receives an object with the path to a dynamic created pdf, and I want to open the pdf. But some browser shows blocked popup
in functions like window.open()
. Then I'm trying to create an anchor and trigger a click on it, but doesn't seems to work:
$http.post('/Export/Create', params).success(function (o) {
load.fadeOut(function () {
if (o.Path.match(/\.pdf$/)) {
console.log('returned PDF');
var a = $('<a></a>').appendTo('body');
a.attr({ 'href': o.Path, 'target': '_blank' });
a.trigger('click');
}
// else ...
});
}).error(function (x) { console.log(x); });
I am receiving the returned PDF
message, so the problem is with the dynamic anchor.
Thanks in advance.