elint

Do not use this if you use the latest SEO extension. The SEO extension now includes an external links in a new tab feature.

I'll still keep this available just in case someone doesn’t use the SEO extension and wants to use this. But, I personally will be going with the SEO extension.

What is this?

A minimal no non-sense Flarum extension which opens only external links in a new tab. Internal links are left alone. Why is it called "elint?" External Links In New Tab.

Some folks ask: Isn't there already an external links extension? Yes/no. There's an extension out there which opens all links in a new tab. This one only touches the external links so that links to other posts (internal links) still open in the same window. This also adds a class called "external-links" to external links so you may style them differently if you'd like. Plus, it ensures external links have "noopener," "nofollow," and "ugc" attributes.

Install

composer require zerosonesfun/elint

Update

composer update zerosonesfun/elint

Remove

composer remove zerosonesfun/elint

Links

https://github.com/zerosonesfun/elint

    010101 Any suggestions for this? And, I mean simple suggestions. I’m not an expert developer. Nothing too crazy please. For example, should I add “nofollow” to the detected external links? Should I add one of those external link icons?

      matteocontrini Good idea. I’ll add noopener. Seems like one day the default for target blank will be noopener. At least that’s what some are pushing. Or, nofollow and noopener together.

      New Release

      • Added noopener and nofollow to external links. One is for security the other is for SEO.

        010101 How about do something like this as there are already nofollow and ugc when needed?

        var rel = $('.External-link').attr('rel');
        $('.External-link').attr('target','_blank').attr('rel',rel + ' noopener');

          Gatsu I believe that one you linked to opens ALL links in an external tab. This only opens external links in a new tab. Internal links, such as ones to another post or page within your forum open in the same window. Therefore, users stay on your site when the link is something on your site, but they leave when the link is not part of your site. This also adds "noopener" which is about security. Many may disagree, but in my opinion, this is how links should work naturally in browsers. If link is part of the site, you stay on that site. If not, you get a new tab/window. Many will also say that you should let the user decide. You can right click and open any link in a new tab. I actually 99% agree with that. EXCEPT, believe it or not, there are users out there who may not know or think about right clicking.

          wloot

          New Release

          • Thanks to wloot, the attributes are now coded better. Now the extension will use the already existing nofollow and ugc in Flarum core, but add the noopener as well for security.
          • The previous poster brought up a good question that you too may be wondering so be sure to read the previous post as well about the difference between this and Franz's external link extension.
          a month later

          Hey, found a bug

          External links have this attribute added to them:

            danielunited Must have something to do with an embed extension. Normal external links I’ve tested do not look like that.

            If you post a normal external link such as, google.com, what happens?

              010101 It happens to all external links - including the ones on the menu. It doesn't happen to internal links (which point to other discussions).

              It's not related to the embed extension. I know because when I dsiabled elint these links work fine (with just nofollow ugc).

                010101 your code is selecting all the links on the page every time a post is rendered, so it adds the attribute many times. jQuery shouldn't really be used with Flarum unless strictly necessary, there's almost always a better way to do it

                  010101 sorry if I've been rude, I just wanted to point out that the Flarum frontend is better extended by using the frontend API and avoiding jQuery as much as possible, so that issues like this are less likely to happen. It's true however that Flarum's extension development is currently very poorly documented so it's quite hard to understand how to do things properly...