/    Sign up×
Community /Pin to ProfileBookmark

RegEx for file download links

Hi, I’m using a little jquery to traverse links on our pages and set a class for different types of urls. Does anyone see a better way to grab file-download links for this? It should run very quickly as we have older machines in our market and a lot of js already.
Thanks!

[code]evans.classlinks = function()
{
var links = $(‘#content-indent .content a’);
for(i=0; i < links.length; i++) {
href = links[i].href.toLowerCase();
if(/(http|https)/.test(href) == true && /localhost|evans.washington/.test(href) == false) {
links[i].className = ‘offsite ‘+ links[i].className;
}
if(/mailto:/.test(href) == true) {
links[i].className = ’email ‘+ links[i].className;
}
if(/(/[-a-zA-Z0-9_?=&;]{0,})$|.(php|htm|html|cgi|pl)$/.test(href) == false) {
//this is also grabbing email links
links[i].className = ‘download ‘+ links[i].className;
}
}
}[/code]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @webnick2007 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...