As already mentioned in the comment, it is impossible to know only from the URL what the browser will do with the link.
The browser reads the response that it gets from the server, and based on the headers in the response it decide what to do (view the page, redirect, download, etc).
I think it will be much better to check on your server-side the links that you create, and if the link is a downloadable-file - add some class to this link:
<a href="file.pdf" class="downloadable">Click to download</a>
And on your javascript code check for <a>
tags that have this downloadable
class:
$('a.downloadable').click(function() {
// Do whatever you need once the link was clicked.
})
Another option (If you really want to) is to send a HEAD
request, parse the response-headers, and based on the headers to decide what to do:
$('a').click(function(e) {
e.preventDefault()
$.ajax({
type: "HEAD",
async: true,
url: URL,
}).done(function(message,text,jqXHR){
// here you can use jqXHR.getResponseHeader('header-name);
});
});
I really advise you against this option, but if you really must do it it's here :)