Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 735233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:27:55+00:00 2026-05-14T07:27:55+00:00

Im trying to take a link either when clicked or hover over be able

  • 0

Im trying to take a link either when clicked or hover over be able to grab the attribute href and tell if its a hyper-link or not. Also i want it to be able to tell me if its a hyper-link to my own site. Plus various other filters.

The main purpose for this is so that when a internal link is clicked it will tell ajax to grab the content, alot of my links are generated (via wordpress)so I can’t modify them too much. Another purpose for this is so i can also make all external links open on a new window.

I have a solution that works on a simple test page but when i put into a working page it breaks. I know i am probably making this harder then it should be.

Here is my code

$(function(){
   $('a').live('click', function(){
      var x = $(this).attr('href');

      $(this).parent('div').append('<div id="test">' + x +'</div>');
      $('#test:contains("http")').css('color', 'red');
      $('#test:contains("sitename")').css('color', 'black');
      $('#test:contains("admin")').css('color', 'red');
      if($('#test').css('color') == 'red'){

         alert('external link');
         $('#test').remove();
         return true; 

      }else{

         alert('external link');
         $('#test').remove();
         return false;

      }
   });
});

thanks for you help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:27:56+00:00Added an answer on May 14, 2026 at 7:27 am
    $('a').live('click', function(){
       var href = $(this).attr('href');
    
       if(/http:\/\//.test(href) || /admin/.test(href)){
          //alert('external link');
          $(this).attr('target', '_blank');
          return(true);
       }
    
       if(/sitename/.test(href)){
          //alert('internal link');
          $.ajax({});
          return(false);
       }       
    }
    

    that is a better approach I guess. Should work, but untested.
    The regex can/and should be fine tuned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to take a rather large CSV file and insert it into
I'm trying to take a POCO object and update it with Linq2SQL using an
So I'm trying to take a bilinear interpolation algorithm for resizing images and add
I am trying to take a shapefile of subdivisions within a county that I
I am trying to take the string <BR> in VB.NET and convert it to
I'm trying to create a custom JSP tag that would take an array object
I'm trying to find out how much memory my objects take to see how
I'm trying to make a calculator that will take inputs from users and estimate
I am trying to write a fragment program that will take a texture and
I'm trying to find the amount of space/width that a string would take when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.