Adding The External Link Icon to Add External Links in Your Website

April 23, 2020

I asked one of my programming friends if he new of an easy way to do this with my current tech stack, and he suggested that I use jQuery. Here is what I came up with after some searching. Proper credit goes to this stack overflow post.

$(document).ready(function(){
    let comp = new RegExp(location.host);
    $('a').each(function(){
        if(comp.test($(this).attr('href'))){
            // a link that contains the current host
            $(this).addClass('localLink');
        }
        else{
            // a link that does not contain the current host
            $(this).addClass('externalLink');

            // make sure this link is not the memu icon link for showing the mobile menu as well as another custom link
            if ((!($(this).attr("data-open") == "jsOffCanvasNav")) && (!($(this).attr("href") == "#main-content-section"))) {
                $(this).append(`
                <svg width="15" height="15" version="1.1" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" role="img" style="vertical-align: middle">
                    <g>
                        <path d="m70.996 60.371v5.7812 8.9141c0 0.86719 0.039062 1.7578-0.058594 2.6172 0.070312-0.51562 0.13672-1.0352 0.20312-1.5625-0.085937 0.65625-0.26562 1.2812-0.50781 1.8945 0.19531-0.46875 0.39063-0.9375 0.58594-1.3984-0.25391 0.59375-0.57812 1.1406-0.96875 1.6602 0.30469-0.39062 0.61719-0.78906 0.91797-1.1797-0.39844 0.50781-0.84766 0.95703-1.3477 1.3477 0.39063-0.30469 0.78906-0.61719 1.1797-0.91797-0.51562 0.39062-1.0625 0.71094-1.6602 0.96875 0.46875-0.19531 0.9375-0.39062 1.3984-0.58594-0.61719 0.25391-1.2422 0.42188-1.8945 0.50781 0.51562-0.070313 1.0352-0.13672 1.5625-0.20312-0.72266 0.085937-1.4648 0.058594-2.1953 0.058594h-3.8281-12.883-15.742-13.477c-2.0898 0-4.1797 0.007812-6.2695 0-0.33203 0-0.65625-0.019532-0.98438-0.058594 0.51562 0.070312 1.0352 0.13672 1.5625 0.20312-0.65625-0.085938-1.2812-0.26562-1.8945-0.50781 0.46875 0.19531 0.9375 0.39062 1.3984 0.58594-0.59375-0.25391-1.1406-0.57812-1.6602-0.96875 0.39062 0.30469 0.78906 0.61719 1.1797 0.91797-0.50781-0.39844-0.95703-0.84766-1.3477-1.3477 0.30469 0.39062 0.61719 0.78906 0.91797 1.1797-0.39062-0.51562-0.71094-1.0625-0.96875-1.6602 0.19531 0.46875 0.39062 0.9375 0.58594 1.3984-0.25391-0.61719-0.42188-1.2422-0.50781-1.8945 0.070312 0.51562 0.13672 1.0352 0.20312 1.5625-0.085938-0.72266-0.058594-1.4648-0.058594-2.1953v-3.8281-12.883-15.742-13.477c0-2.0898-0.007812-4.1797 0-6.2695 0-0.33203 0.019531-0.65625 0.058594-0.98437-0.070313 0.51562-0.13672 1.0352-0.20312 1.5625 0.085937-0.65625 0.26562-1.2812 0.50781-1.8945-0.19531 0.46875-0.39062 0.9375-0.58594 1.3984 0.25391-0.59375 0.57812-1.1406 0.96875-1.6602-0.30469 0.39062-0.61719 0.78906-0.91797 1.1797 0.39844-0.50781 0.84766-0.95703 1.3477-1.3477-0.39062 0.30469-0.78906 0.61719-1.1797 0.91797 0.51562-0.39063 1.0625-0.71094 1.6602-0.96875-0.46875 0.19531-0.9375 0.39062-1.3984 0.58594 0.61719-0.25391 1.2422-0.42188 1.8945-0.50781-0.51562 0.070313-1.0352 0.13672-1.5625 0.20313 1.2969-0.15625 2.6562-0.058594 3.9648-0.058594h8.0664 9.9023 8.6719c1.4062 0 2.8125 0.019531 4.2188 0h0.058594c1.5039 0 3.0781-0.65625 4.1406-1.7188 1.0156-1.0156 1.7773-2.6875 1.7188-4.1406-0.070312-1.5156-0.56641-3.0859-1.7188-4.1406-1.1406-1.0547-2.5586-1.7188-4.1406-1.7188h-5.4219-11.855-11.699-3.7383c-0.68359 0-1.375-0.03125-2.0508 0.046875-2.3633 0.24219-4.707 0.83984-6.6406 2.2969-0.63281 0.48047-1.2891 0.94531-1.8555 1.5039-0.42188 0.42188-0.77344 0.89062-1.1328 1.3594-0.35156 0.44922-0.70312 0.89844-0.99609 1.3867-0.41016 0.71094-0.72266 1.5156-1.0234 2.2656-0.60547 1.5156-0.78125 3.1953-0.78125 4.8125v5.8203 10.566 12.664 12.102 8.8594c0 2.0781-0.070313 4.0938 0.37109 6.1523 0.48828 2.2734 1.7695 4.4062 3.3398 6.0859 0.78125 0.83984 1.7383 1.5625 2.7148 2.168 0.29297 0.1875 0.59375 0.34375 0.91016 0.48047 0.75 0.34375 1.5234 0.69531 2.3125 0.91797 1.3477 0.39062 2.7656 0.49609 4.1602 0.49609h6.1133 10.734 12.695 12 8.625c2.2188 0 4.5312 0.125 6.6602-0.59375 2.1875-0.74219 4.3164-1.9414 5.8398-3.7109 0.75-0.87891 1.5234-1.8359 2.0234-2.8984 0.48047-1.0469 0.97656-2.1289 1.1641-3.2617 0.27344-1.6719 0.3125-3.1641 0.3125-4.8359v-11.68-2.6367c0-1.5039-0.65625-3.0781-1.7188-4.1406-1.0156-1.0156-2.6875-1.7773-4.1406-1.7188-1.5156 0.070313-3.0859 0.56641-4.1406 1.7188-1.0312 1.1523-1.6953 2.5586-1.6953 4.1484z"/>
                        <path d="m97.258 36.203v-6.8555-10.938-2.5312c0-3.1641-2.6875-5.8594-5.8594-5.8594h-6.8555-10.938-2.5312c-1.5039 0-3.0781 0.65625-4.1406 1.7188-1.0156 1.0156-1.7773 2.6875-1.7188 4.1406 0.070312 1.5156 0.56641 3.0859 1.7188 4.1406 1.1406 1.0547 2.5586 1.7188 4.1406 1.7188h6.8555 10.938 2.5312c-1.9531-1.9531-3.9062-3.9062-5.8594-5.8594v6.8555 10.938 2.5312c0 1.5039 0.65625 3.0781 1.7188 4.1406 1.0156 1.0156 2.6875 1.7773 4.1406 1.7188 1.5156-0.070312 3.0859-0.56641 4.1406-1.7188 1.0547-1.1445 1.7188-2.5508 1.7188-4.1406z"/>
                        <path d="m49.367 66.191 4.6016-4.6016c3.6836-3.6836 7.3633-7.3633 11.047-11.047l24.844-24.844c1.875-1.875 3.7578-3.7188 5.6172-5.6172 0.03125-0.03125 0.046876-0.046875 0.078126-0.078125 1.0625-1.0625 1.7188-2.6367 1.7188-4.1406 0-1.4375-0.63281-3.1523-1.7188-4.1406-1.1133-1.0234-2.5781-1.7891-4.1406-1.7188-1.5547 0.070313-3.0156 0.59375-4.1406 1.7188-1.5312 1.5312-3.0664 3.0664-4.6016 4.6016-3.6836 3.6836-7.3633 7.3633-11.047 11.047l-24.844 24.844c-1.875 1.875-3.7578 3.7188-5.6172 5.6172-0.03125 0.03125-0.046874 0.046875-0.078124 0.078125-1.0625 1.0625-1.7188 2.6367-1.7188 4.1406 0 1.4375 0.63281 3.1523 1.7188 4.1406 1.1133 1.0234 2.5781 1.7891 4.1406 1.7188 1.5508-0.066406 3.0156-0.59766 4.1406-1.7188z"/>
                    </g>
                </svg>
            `);
            }
        }
    });
});
Personal Updates

This is a password protected section available to those who know me in some fashion. If you know me and you do not already have a login, you can request a login here.

Personal Updates
Book Reviews

I am nuts about books. I read on all kinds of topics. I attempt to review each book I read for the sake of my own enrichment as well as conversation starters with others.

My Book Reviews
Pastoral Ministry

God has called me to be a pastor, and occasionally I have some pastoral thoughts I like to share.

Pastoral Posts
The Attic

You never know what you will find in an attic! Usually there is a hodgepodge of things buried under dust.

Explore the Attic
Technology

Most of what is included here are notes to myself. The majority of folks will not find interest in these posts.

Technology Posts