How can I open a pdf file in a new window or download a pdf file on button click?
How can I open a pdf file in a new window or download a pdf file on button click?
JNeed86
Posts: 1Questions: 1Answers: 0
Everything works fine until it gets to the "window.open(pdf, '_blank');
line. Then it will auto refresh the page and does not open the pdf file. Can someone tell me what I am doing wrong here? All I want it do is open the PDF file OR download it, does not matter which one. Be gentle, I am new to Jquery, HTML, and ASP.net.
$(document).ready(function () {
var table = $('#table_id').DataTable(
{
dom: 'Blfrtip',
searching: true,
select: true,
buttons: ['copy', 'excel', 'csv', 'pdf'],
"columnDefs": [{
"targets": -3,
"data": null,
"defaultContent": "<button>Open</button>"
}]
});
$('#table_id tbody').on('click', 'button', function () {
var data = table.row($(this).parents('tr')).data();
var pdf = "D:\\TMT\\TCS\\HubData\\BOL\\" + data[3] +".pdf";
alert(data[3] + "s location is: " + pdf);
window.open(pdf, '_blank');
});
});
This discussion has been closed.
Answers
That's not an Editor or Data Tables specific question. I would just google how to do this.
Here are the basics:
https://www.w3schools.com/howto/howto_html_download_link.asp
and from SO:
https://stackoverflow.com/questions/2793751/how-can-i-create-download-link-in-html
But you'll find a lot more ...