jquery - Most efficient way to determine if HREF is file or redirect -


i'm working on smart script reports button/link clicks ga. i'd separate redirects file downloads. tag used a href attribute specified.

so let's have following hrefs:

"/" "aboutus/" "//www.google.com" "file1.txt" "file2.pdf" "file3.jpeg" 

would efficient approach having array possible file extensions , matching href or should regex or else?

as mentioned in comment, impossible know url browser link.

the browser reads response gets server, , based on headers in response decide (view page, redirect, download, etc).

i think better check on server-side links create, , if link downloadable-file - add class link:

<a href="file.pdf" class="downloadable">click download</a> 

and on javascript code check <a> tags have downloadable class:

$('a.downloadable').click(function() {     // whatever need once link clicked. }) 

another option (if want to) send head request, parse response-headers, , based on headers decide do:

$('a').click(function(e) {     e.preventdefault()     $.ajax({         type: "head",         async: true,         url: url,     }).done(function(message,text,jqxhr){         // here can use jqxhr.getresponseheader('header-name);     }); }); 

i advise against option, if must it's here :)


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -