Styling external links with text or icon is common practice for many
sites, like Wikipedia. It serves as a simple visual cue indicating that
if you click a particular link you will be taken to another site.
You can simply implement this using CSS or JavaScript without having to add any additional elements to your anchor tags or additional image tags to the HTML source.
Example is given below:
CSS Solution
You can archive that with common HTML and CSS like this:
HTML:
<a href="#" class="external">external link</a>
CSS:
.external a {
background: url(external.jpg) center right no-repeat;
margin: 0 12px 0 0;
}
<a href="#" class="external">external link</a>
CSS:
.external a {
background: url(external.jpg) center right no-repeat;
margin: 0 12px 0 0;
}
Imagine the extra work you have do while passing class="external" to all external links, which is easy enough for you to forget.
However, there's a CSS that can apply the indicator icon to all external links:
a[href^="http://"],
a[href^="https://"] {
background: url(external.jpg) center right no-repeat;
margin: 0 12px 0 0;
}
a[href^="https://"] {
background: url(external.jpg) center right no-repeat;
margin: 0 12px 0 0;
}
There are two common urls, like http://www.google.com and https://www.google.com/webmasters. So we have target the two protocols with href^="http://" and href^="https://".
Now, the code above will apply the icon to all links starting with http:// and https:// (including links to your own domain). Luckily there's a way we can play around this. What we have to do is, declare a rule matching links that start with http:// and https:// with the current page domain and set the background and margin values back to the defaults.
If I'm to do that for this blog, I will write something like this:
a[href^="http://www.realcombiz.com"] {
background: "";
margin: 0;
}
background: "";
margin: 0;
}
The above code will prevent the external icon style on that specific url.
You can also style external link in your web pages with target="_blank" only if that in your visual editor you check that the link should open in new tab. The code that does the magic is as follow:
a[target="_blank"] {
background: url(external.jpg) center right no-repeat;
margin: 0 12px 0 0;
}
background: url(external.jpg) center right no-repeat;
margin: 0 12px 0 0;
}
Using Font Awesome
If you have Font Awesome installed you can use the following:
a[target="_blank"]:after {
font-family: 'FontAwesome';
content: " \f08e";
}
font-family: 'FontAwesome';
content: " \f08e";
}
That f08e is called unicode. It is readable by your browser and is ultimately what renders your icon.
Note: If you use an icon font other than Font Awesome, you will need to change the font-family to the name of the font you are using to render your icons.
JavaScript Solution
With JavaScript you can also display icon after external link. The technique is simple: we simply declare a rule that select element with id content, but you will need to make sure the id tally with the id that wraps your content, then we select all the anchor links within the page with getElementsByTagName( 'a' ).
var length = document.getElementById('content').getElementsByTagName('a').length;
var href;
for(var i=0;i<length;i++)
{
href = document.getElementById('content').getElementsByTagName('a').item(i).getAttribute('href');
if(!href.match(/your-site.com/))
{
document.getElementById('content').getElementsByTagName('a').item(i).innerHTML = document.getElementById('content').getElementsByTagName('a').item(i).innerHTML + "<img src='external.jpg'/>";
}
}
var href;
for(var i=0;i<length;i++)
{
href = document.getElementById('content').getElementsByTagName('a').item(i).getAttribute('href');
if(!href.match(/your-site.com/))
{
document.getElementById('content').getElementsByTagName('a').item(i).innerHTML = document.getElementById('content').getElementsByTagName('a').item(i).innerHTML + "<img src='external.jpg'/>";
}
}
Now to differentiate external link from internal, we set a rule that check if the current link is external or not. If the link contains the domain name your-site.com then the code in the 'if' block will not be executed. But it finds any link other than your-site.com it will add <img src='external.jpg'/> to its current HTML code.
Subscribe For Free Updates!
*Please confirm the email sent to your inbox after clicking "Sign Up!".
This is very interesting post! By following your given points one can add icons to their website and make a more impressive website design.
ReplyDeleteTricksabout.net
ReplyDeleteinternet Tricks
Blogging Tricks
Thanks for this codes im gonna try this to my proj. thanks a lot
ReplyDeleteGary Volk Design Reviews
This is a great exciting article. I am pretty much satisfied with your good work. You put really very useful information. I am delighted to see that people are in fact writing about this subject in such an elegant method, presenting us all diverse parts to it.
ReplyDeleteessay writing service reviews
Im no expert, but I believe you just made an excellent You certainly understand what youre speaking about, and I can truly get behind that.
ReplyDeleteRegards,
Python Training|Python Training Institutes in Chennai|python training in chennai
Great post. having a business sector benevolent substance, and including a fundamental checkout and uncomplicated shopping basket. website design
ReplyDeleteFoto Bugil
Deletehammer of thor
hammer of thor
Foto Memek
Foto Ngentot
funny valentine ecards 2016
ReplyDeletevalentine day lovely couple wallpaper
valentine day gifts for him
valentines day for him
valentines day history story with images
valentines day facts about girlfriend spouse
creative valentines day 2016 ideas for gfbf
happy valentines day hd wallpaper 2016
cute valentines day quotes for girlfriend
homemade valentines cards new ideas
valentine wishes messages cards for friends
happy valentines day quotes
love wallpapers for valentines day
when is rose day
printable valentines day cards ideas
valentine week information
Great post with amazing website designing and development with very low rates thanks for sharing website design and development
ReplyDeleteExcellent post!!! The future of .net application development is on positive note. It offers huge career prospects for talented professionals all over the world. Training on .net technology will ensure good salary package. Best DOT NET Training in Chennai|Dot net courses in chennai |.net training in chennai|.net course in chennai
ReplyDeletehttp://congnghe.tech76.vn/threads/pho-ga-tron.16723/
ReplyDeletehttp://danthucpham.vn/threads/pho-ga-tron.63427/
http://forum.giadinhso1.com/threads/pho-ga-tron.12818/
http://forums.nicewebz.com/threads/pho-ga-tron.322336.html
http://hivietnam.org.vn/threads/pho-ga-tron.24062/
http://kythuatcongnghemay.com/threads/pho-ga-tron.22940/
http://raovat5giay.com/threads/pho-ga-tron.42514/
http://raotot.net/threads/pho-ga-tron.50365/
http://raomua247.com/threads/pho-ga-tron.381637/
http://modamodelleri.org/threads/pho-ga-tron-hap-dan.6658
http://bogorsehat.com/threads/pho-ga-tron-hap-dan.5059
http://muabannhadat.mobi/vn/threads/pho-ga-tron-hap-dan.11927/
http://muabanxehoi.mobi/vn/threads/pho-ga-tron-hap-dan.14809/
http://chotot.us/vn/threads/pho-ga-tron-hap-dan.25742/
http://padangpasir.com/threads/pho-ga-tron-hap-dan.6333
http://cameradslr.net/threads/pho-ga-tron-hap-dan.6395
http://tuoitre.us/vn/threads/pho-ga-tron-hap-dan.22966/
http://www.lankew.com/threads/canh-ga-chien-xu.5095
http://chothuevanphongvn.com/4rum/t/canh-ga-chien-xu.2895
http://www.aloudgroup.co/threads/canh-ga-chien-xu.4985
N
ReplyDeleteBOOM BEACH FOR PC
BOOM BEACH FOR PC
BOOM BEACH FOR PC
BOOM BEACH FOR PC
BOOM BEACH FOR PC
BOOM BEACH FOR PC
BOOM BEACH FOR PC
BOOM BEACH FOR PC
BOOM BEACH FOR PC
BOOM BEACH FOR PC
BOOM BEACH FOR PC
BOOM BEACH FOR PC
BOOM BEACH FOR PC
BOOM BEACH FOR PC
BOOM BEACH FOR PC
BOOM BEACH FOR PC
Tango For Pc
Tango For Pc
Tango For Pc
Tango For Pc
Tango For Pc
Tango For Pc
Tango For Pc
Tango For Pc
Tango For Pc
Tango For Pc
Tango For Pc
Tango For Pc
Tango For Pc
Tango For Pc FOR PC
Tango For Pc FOR PC
Tango For Pc FOR PC
Tango For Pc FOR PC
Tango For Pc FOR PC
Tango For Pc FOR PC
I have seen so many sites that provide java programming homework help but nothing satisfied me. I need some authentic resources that can genially help me.
ReplyDeleteHappy Thanksgiving 2016 Images
ReplyDeleteThanksgiving Jokes
Happy Thanksgiving Turkey Images Pics Free Download Turkey Jokes, Memes, Trolls, Quotes & Wishes
Best Pumpkin designsHalloween Celebration Tradition
IOS has recently launched new version of Apple Operating System called IOS 10.To upgrade your IOS to Latest IOS 10 new release by Apple Inc. you can get New iOS 10 free from CydiaNerd on your Browser.
ReplyDeleteVisit for find valentines day images and greeting - http://www.happyvalentinesdaywishess.com
ReplyDeleteeaster images
ReplyDeletehappy easter wishes messages
greetings for easter
easter greeting cards
It’s really a great and helpful piece of line. I am glad that you shared this helpful info with us. Please keep us informed like this.
ReplyDeleteThanks for sharing
whatsapp web
Thank you for bringing more information to this topic for me. I’m truly grateful and really impressed. Really appreciate for your amazing article. Thank you for this valuable information. filmywap apk
ReplyDeleteThe counterfeit plants can expand the tasteful excellence of the whole climate. Henceforth they are considered as a need as opposed to a mold image. There is no additional cost for support while it is comprehending your motivation. Read more
ReplyDeleteBest javascript blog.
ReplyDeleteIMO for pc
IMO for windows 10
IMO for MAC
Tubemate for pc
Tubemate for windows 10
It is a great article. You will surely like this also because it is a great stuff, yeah it’s give us lots of interest and pleasure. Their opportunities are so fantastic and working style so speedy. Thank you for sharing the nice article. fastpokemap
ReplyDeleteThanks for your article, it gave me a lot of new and useful information. Hope you have more posts to share with everyone.
ReplyDeletebloxorz
The strategy you have updated here will make me to get trained in future technologies. By the way you are running a great blog. Thanks for sharing this.nice information about this valuable article,which helps to learn more
ReplyDeleteWeb designing course in chennai
Thanks for your article! Although simple, but your posts have made it more attractive and interesting!
ReplyDeleteWP Master Developer Pro review - the update from JavaScript Editor – a best-selling product with comprehensive assistance for coders!
ReplyDeletehttps://plus.google.com/106262987256055046214/posts/d9hbvcBBrEL
https://www.pinterest.com/johnnynguyenagb/agb-review/
http://video.vitalk.vn/video/7186/wp-master-developer-pro-review-code-editor-for-wordpress/
The sites you have referred were good. This is a great article, that I really enjoyed reading. Thanks for sharing. http://ssapptricks.com/yelp/
ReplyDeleteopen in the Yelp app
Nice Blog....Thanks for sharing this informative article.
ReplyDeleteDot Net Training in Chennai | Dot Net Training Institute in Chennai | Online Training in Chennai
Awesome share...Thanks for sharing this useful information.
ReplyDeleteasp .net web development company.
asp .net development services.
Custom application development company.
dot net development companies in chennai.
Good post..Keep Sharing.! I'm working in brave technologies private limited. We are the leading ERP software development company in chennai.
ReplyDeleteGood post..Keep Sharing.! fetlife apk download.
ReplyDeleteGood post..Keep Sharing.! fetlife apk download.
ReplyDeletepolo outlet
ReplyDeletecoach outlet online
coach outlet online
michael kors outlet
coach outlet
polo ralph lauren
polo ralph lauren outlet online
cheap ray ban sunglasses
longchamp outlet
oakley sunglasses wholesale
20170528wanglili
Great post! I really like the presentation of your article. It is really nice to read. Keep sharing more such posts.
ReplyDeleteMobile Testing Training in Chennai
Mobile Appium Training in Chennai
Ionic Training in Chennai
Placement Training in Chennai
Excel Training in Chennai
VMware Training in Chennai
Microsoft Dynamics CRM Training in Chennai
it was a wonderful chance to visit this kind of site and I am happy to know. thank you so much for giving us a chance to have this opportunity.. This is the exact information I am been searching for, Thanks for sharing the required infos with the clear update and required points.
ReplyDeleteDot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery
Enjoyed reading the article above , really explains everything in detail, the article is very interesting and effective. Thank you and good luck for the upcoming articles. To know step by step process use in mictest
ReplyDeletewhile using different types of microphones for various purposes visit this profile this is something will help you out.