Navigation Placeholder

Archive

Show more

Add Target To Link Lists...

After exercising the nuclear option and not having a sidebar, I had a compelling need to cram one more thing into my already overstuffed footer. I wanted a couple of external links to a handful of sites. Unfortunately, the standard Link List widget in Blogger doesn't allow one to specify that a given link should open in a new window. When researching previous efforts on this subject, there are a number of solutions that boil down to either using a script or editing your theme. As I'm not inclined towards editing my theme, I'll be adding my script to the pile of solutions that already exist.
As a blogger, using rel="noopener noreferrer" on links that open in a new tab (target="_blank") is critical for protecting your website from security vulnerabilities and controlling how your traffic data is shared. When you write a blog post and set an external link to open in a new tab, the browser automatically grants the new page a tiny bit of access to your original page. If that destination site happens to be hacked or malicious, it can exploit this connection.
Add the following script to an HTML/JavaScript widget and place it somewhere after the Link List widget(s) in your layout. In the Contempo and Essential templates, this is usually at the bottom of the sidebar, but, as I'm not using a sidebar, I've placed my script at the bottom of my footer.
<script type="text/javascript">

function Do_LinkLists() {
var d=document;
var linkDivs=d.getElementsByClassName("widget LinkList");
if ((new String(linkDivs)!="null") && (new String(linkDivs)!="undefined")){
for (a=0;a<linkDivs.length;a++){
const allLinks=linkDivs[a].getElementsByTagName("a");
for (l=0;l<allLinks.length;l++){if (allLinks[l].href.indexOf("aarg")<0) { /* Doesn't have keyword */
allLinks[l].target="_blank";
allLinks[l].setAttribute("rel","noopener noreferrer"); /* Optional: Recommended for security purposes */
}}}}}

Do_LinkLists();

</script>
This code functions by examining every Link List widget in your layout and checking each link for a keyword. You'll need to change the yellow highlighted keyword in the code above to something appropriate for your site. If your site is example123.blogspot.com or www.example123.com, then your keyword would be example123. Also, according to AI-powered advice, the noopener/noreferrer tags can adversely affect affiliate links. If you don't want these added to your links, you can safely remove the entire line. Feel free to use this or not as you see fit.

That's all for today. Enjoy.

Comments