SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2007
    Location
    Atlanta, GA
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    External link warning message on all 'href' links EXCEPT one?

    I have this script and it's working pretty well. Except now I need it to not give the message on one single external link.

    Code JavaScript:
    $(document).ready(function() {
     
      // Creating custom :external selector
      $.expr[':'].external = function(obj){
          return !obj.href.match(/^mailto\:/)
                  && (obj.hostname != location.hostname);
      };
     
      // Add 'external' CSS class to all external links
      $('a:external').addClass('external');
     
      $('.external').click(function() {
        var link = $(this).attr('href');
     
        $('<div>By clicking \'Okay\' you will be transferred to a web site not controlled by xxxxxxxxxx. xxxxxxxxxxx is not responsible for any of the info or services provided by this web site. The web site you are about to access is not covered by xxxxxxxxxxxxx privacy policy or security statement. <br /> <strong>Are you sure you want to proceed?</strong></div>').dialog({
          title: "External Link",
          modal : true,
          overlay: {
            backgroundColor: '#000',
            opacity: 0.5
          },
          buttons: {
            'Okay': function() {
              $(this).dialog('close').remove();
              window.open(link);
            },
            'Cancel': function() {
              $(this).dialog('close').remove();
              return false;
            }
          }
        });
     
        return false;
      });
    });

    This works on any "href" external link or link with class of "external". I have one link that needs to be added that is external but needs to appear to not be and not give the warning message.

    Can you help me with an exception to this script? Thanks!

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2007
    Location
    Atlanta, GA
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I figured this out by adding "$('a.password').removeClass('external');" right after the addClass. It works, moving on...

  3. #3
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,299
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by cAPS lOCK View Post
    Ok, I figured this out by adding "$('a.password').removeClass('external');" right after the addClass. It works, moving on...
    That was clever. I didn't offer a suggestion, as I'm not good enough a jQuery, but subscribed to see where this went.) Was wondering about the first bit of the code, though. I'm assuming it's a regular expresssion to prevent the behavior on mailto links, so was wondering if there's a way to extend it for the password url.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •