I’m using jQuery to select internal links and do cool ajax stuff.
$(‘a[href^=”‘+ base_url +'”])
This works fine, but what if we link to external resources? Like jpeg or pdf’s hosted on our site? It breaks. So I added this to the selector:
$(‘a[href^=”‘+ base_url +'”]:not(a[href$=”jpg”]):not(a[href$=”jpeg”]):not(a[href$=”gif”]):not(a[href$=”png”])’)
It’s ugly and it doesn’t cover all extensions. How can I use JavaScript to detect it’s an external file and should not be ajaxed? And not all extensions, for example I may build a .php file and link to that. It’s just a regular page.