I would like to know how I can check if a url with a certain file has the pdf extension, in my code if the url has a pdf file a modal will be opened, if it is any other extension nothing happens.
I tried doing this using: if (/pdf/.test(document.file))
As document.file the link from my file.
But something is wrong, maybe the syntax of the code I should be confused with the + and the "" in the html part.
My code is:
for(var key in data.val()){
documento = data.val()[key]
linha = "<tr>"+
"<td>"+documento.titulo+"</td>"+
"<td>"+documento.data_inicio+"</td>"+
"<td>"+documento.categoria+"</td>"+
if (/pdf/.test(documento.arquivo)){+
"<td class='view'><a data-toggle='modal' data-target='#myModal' data-link='"+documento.arquivo+"'><i class='fa fa-eye'></i></a></td>"+
}+
"</tr>";
$('#tableCustom tbody').append(linha);
$(".view a").on( "click", function() {
var link = $(this).data('link');
PDFObject.embed(link, ".modal-content");
});
}