WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.6 is now available!


Will it continue with WB? It goes on! | Geht es mit WB weiter? Es geht weiter!
https://forum.websitebaker.org/index.php/topic,32340.msg226702.html#msg226702


The forum email address board@websitebaker.org is working again
https://forum.websitebaker.org/index.php/topic,32358.0.html


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker


  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • General Community »
  • Off-Topic »
  • Automatic external links and rel="noopener"
  • Print
Pages: [1]   Go Down

Author Topic: Automatic external links and rel="noopener"  (Read 6016 times)

Offline Hans

  • Posts: 914
  • Gender: Male
Automatic external links and rel="noopener"
« on: May 14, 2017, 08:54:47 PM »
Hello,
unless my client doesn't want that "feature" I always place this code in my templates to force external links to open in a new tab.
Code: [Select]

<script type="text/javascript">
$(document).ready(function () {
$("a").filter(function () {
return this.hostname && this.hostname !== location.hostname;
}).addClass('external').attr("target", "_blank");
});
</script>

Now I have read that there might be safety issues and negative impact on quick rendering of a page.

To avoid those it's advisable to add
Code: [Select]
rel="noopener" to the link.

I don't know however how to change the code so that
Code: [Select]
rel="noopener" is part of the resulting link.

Hope someone can help me, I'm no coder.

Logged
Hans - Nijmegen - The Netherlands

Offline Ruud

  • Posts: 3671
  • Gender: Male
  • Do not use PM for help! Please use the forum!
    • Dev4Me - Professional WebsiteBaker Development
Re: Automatic external links and rel="noopener"
« Reply #1 on: May 14, 2017, 10:37:08 PM »
The jQuery function attr() also allows objects/arrays to be processed.

You can change the part:
Code: [Select]
.addClass('external').attr("target", "_blank");
into:
Code: [Select]
.addClass('external').attr({
    target : "_blank" ,
    rel : "noopener"
});
Logged
Dev4me - WebsiteBaker modules - WBhelp.org

Offline Hans

  • Posts: 914
  • Gender: Male
Re: Automatic external links and rel="noopener"
« Reply #2 on: May 15, 2017, 01:16:37 PM »
Great, thanks Ruud!
Logged
Hans - Nijmegen - The Netherlands

Offline Manuela

  • Posts: 1
  • Gender: Female
Re: Automatic external links and rel="noopener"
« Reply #3 on: June 04, 2017, 03:48:22 PM »
only a test...
Logged

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • General Community »
  • Off-Topic »
  • Automatic external links and rel="noopener"
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2