RegEx expression or jQuery selector to NOT match "external" links in href
- by TrueBlueAussie
I have a jQuery plugin that overrides link behavior, to allow Ajax loading of page content. Simple enough with a delegated event like $(document).on('click','a', function(){});.
but I only want it to apply to links that are not like these ones (Ajax loading is not applicable to them, so links like these need to behave normally):
target="_blank" // New browser window
href="#..." // Bookmark link (page is already loaded).
href="afs://..." // AFS file access.
href="cid://..." // Content identifiers for MIME body part.
href="file://..." // Specifies the address of a file from the locally accessible drive.
href="ftp://..." // Uses Internet File Transfer Protocol (FTP) to retrieve a file.
href="http://..." // The most commonly used access method.
href="https://..." // Provide some level of security of transmission
href="mailto://..." // Opens an email program.
href="mid://..." // The message identifier for email.
href="news://..." // Usenet newsgroup.
href="x-exec://..." // Executable program.
href="http://AnythingNotHere.com" // External links
Sample code:
$(document).on('click', 'a:not([target="_blank"])', function(){
var $this = $(this);
if ('some additional check of href'){
// Do ajax load and stop default behaviour
return false;
}
// allow link to work normally
});
Q:
Is there a way to easily detect all "local links" that would only navigate within the current website? excluding all the variations mentioned above.
Note: This is for an MVC 5 Razor website, so absolute site URLs are unlikely to occur.