Problem/Motivation

Core adds target="_blank" to a number of external URLs. In general, this is not a good accessibility practice. The WCAG guidelines indicate that it is only usually recommended in when (for example) the user is in the middle of something like a multi-step form.

Proposed resolution

Update links as needed according to the Accessibility core gate. In particular, the use of WCAG 2.1, Opening new windows and tabs from a link only when necessary: Either remove the target="_blank", or update the string to inform the user that a new window will be opened.

Also, consider a followup to provide better accessibility guidance about the attribute in this string:

core/modules/views/src/Plugin/views/field/FieldPluginBase.php:        '#description' => $this->t("Target of the link, such as _blank, _parent or an iframe's name. This field is rarely used."),

(That might be wontfix, but it is worth considering.)

Remaining tasks

  1. Search core and identify all the places we add target="_blank".
  2. Document them here on the issue.
  3. Sort them into the following categories:
    1. The installer or update.php
    2. Other multistep forms or complex user interactions
    3. Single-step forms
    4. Not a form at all (e.g., the frontpage view, the status report.)
  4. For categories 1 and 2, a single child issue should be filed to ensure all the links warn the user that a new window will be opened.
  5. For category 3, we will probably need accessibility feedback on which way to go.
  6. For category 4, a single child issue should be filed to remove all the target="_blank" from those strings.

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-2652272

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

imrancluster created an issue. See original summary.

imrancluster’s picture

suraj1074’s picture

StatusFileSize
new2.07 KB

The patch does not apply. Even when i create the same patch by manually doing the change. I created the .diff extension file it applies. I am a newbie am i doing any error?

Status: Needs review » Needs work

The last submitted patch, 3: mypatch.diff, failed testing.

himanshugautam’s picture

StatusFileSize
new4.34 KB
imrancluster’s picture

@suraj1074
If you have drupal core 8.1.x installed then this patch should be run. You can clone using the following url-
git clone --branch 8.1.x https://git.drupal.org/project/drupal.git

After creating the patch I use the following command to apply the patch with 8.1.x branch. It worked for me.
git apply -v [patchname.patch]

himanshugautam’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: Target_blank_added-2652272-2.patch, failed testing.

mallezie’s picture

Issue tags: +Needs backport to D7

The patch applies cleanly, and works as announced.
However this only fixes the links to the date php settings. When looking through drupal core, there are lot's of places a link to an external site (mostly drupal.org / php.net and wikipedia) are shown. (For example status report page). Should we be able to fix those in one go?
This probably needs some grep magic to find them all. Some are to http / https sites, and contained in the a tag, others are escaped, and the link is added afterwards.

imrancluster’s picture

@mallezie Yes we can.

Actually I am new in contributing world :)
This is my first very small patch, you know :(, I have no commit for Drupal core or any contrib modules.
But I am interested and learning how to contribute right way

vishwac9’s picture

Status: Needs work » Fixed

Changing the bug status to fixed, the patch works well ! Just to ask have you committed your local code after applying the patch.

imrancluster’s picture

@vishwac9 I commited in my laptop, but I didn't push to live 8.1.x. I have no idea about this.

Should I push my commit to live branch?

vishwac9’s picture

@imrancluster we cannot push back to the core. It would be taken care by the core team. Actually, my answer was intended to suraj1074 sorry for the confusion :)

mallezie’s picture

Status: Fixed » Needs review
imrancluster’s picture

@mallezie

Here is a updated patch. I updated for the all following external urls-

php.net
en.wikipedia
www.drupal
ckeditor.com
www.w3.org

Status: Needs review » Needs work

imrancluster’s picture

Target-_blank-attribute-add-to-to-external-links-2652272-15.patch

This patch worked for my 8.1.x. I don't know, why this test pass was failed.

wiifm’s picture

Before we go ahead and break most translatable strings in Drupal, has anyone done some research as to why this is a good idea?

From reading https://css-tricks.com/use-target_blank/ it comes up with clear examples on when target=_blank should be used. A blanket "internal and external" rule seems to make little sense.

Keen to hear some more justification on this. Also, if this is restricted to just where places where it makes the most sense, can this be targeted at 8.0.x ?

Saphyel’s picture

Assigned: Unassigned » Saphyel
Saphyel’s picture

Status: Needs work » Needs review
Issue tags: +SprintWeekend2016
StatusFileSize
new198.92 KB

I updated the ckeditor changes

Saphyel’s picture

Assigned: Saphyel » Unassigned

Status: Needs review » Needs work
bhavikshah9’s picture

I think, it is too big to be done in one shot. It will be very difficult to debug why patch failed, because there are many files involved.
Let's chunk it into pieces with one issue for each module. Remaining files can be grouped into one last shot.
Would like to hear feedback on this.

lomasr’s picture

Title: Target="_blank" attribute add to to external links. » Target="_blank" attribute add to external links.

Grammer correction in the title.

lomasr’s picture

Assigned: Unassigned » lomasr
lomasr’s picture

Issue tags: +drupalconasia2016
lomasr’s picture

Assigned: lomasr » Unassigned
neelanjana das’s picture

This patch opens the php manual in a new tab using jquery.

neelanjana das’s picture

Assigned: Unassigned » neelanjana das
Status: Needs work » Needs review

Status: Needs review » Needs work
imrancluster’s picture

I think, to take decision for this issue will be more difficult. When I created this issue I found some external links. I don't know the actual philosophy of external url usages. Now I am realizing If we apply target attribute for external urls what will be the action for like apple tabs and other smart devices.

We should think both device's behavior. I'm a new person, so I don't know what will be happening for this issue.

neelanjana das’s picture

Assigned: neelanjana das » Unassigned
swaps’s picture

Assigned: Unassigned » swaps

@imrancluster : Don't really have to worry about its behavior on different devices as its suppose to be behavior is clearly defined here.

@Neelanjana Das : We don't really need to have a JS snippet for this implementation. Please user target=_blank instead.

Cheers,
SwapS.

swaps’s picture

Assigned: swaps » Unassigned

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

timhtheos’s picture

Version: 8.2.x-dev » 8.1.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.97 KB

I just reload the latest passed patch against 8.1.x-dev.

swaps’s picture

Patch on #37 looks good.
Works as expected for Date module fixes.

Also , as suggested by @bhavikshah9 ; we should create separate issues for fixing it for other module (should have one primary ticket to track it to closure.)

Cheers,
SwapS.

imrancluster’s picture

@SwapS
That will be good. I created a patch for all modules, for some external sites. See #15
That's why the patch was failed. :(

catch’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update, +Needs usability review

This is generally discouraged - there's plenty of ways to open a link in a tab. Tagging for an issue summary update as to why we'd do this vs. letting people choose, and for usability review.

yoroy’s picture

I don't think we've defined a standard for this. It is generally discouraged indeed. How many of these kinds of links are there in core?

The real solution for the specific case of setting a date format would be a better UI for it that doesn't rely on external documentation to make it work. Something more than a single text field :)

cameron tod’s picture

mpdonadio’s picture

Hopefully @Bojhan will hop into this as we were just discussing this in IRC.

The problem is that core isn't consistent in how target=_blank is used. I don't think a blanket "all external links should open in new windows" is appropriate.

I would propose that we use this for all external links when a link is used on a form / wizard, or anywhere else user input may be lost when they navigate to a new page. I also think that in addition to target=_blank, we should add rel=external to them for improved accessibility for devices that grok this.

For sanity, I would be in favor of scoping the issues to links out to a particular site, but not by module. So, we rescope this issue to be all links out to php.net and then evaluate other sites (any maybe one issue to mop up the one-offs).

I will update the IS later with arguments for both sites.

#41, that is really unfeasible as the link is related to custom date formatters where you need to know the PHP syntax / placeholder codes; there are already standard formatters that are user-friendly. There are a decent number of these links in core out to external resources, but not a ton.

yoroy’s picture

I'd say having to know the PHP syntax / placeholder codes to set a custom date format is the unfeasible part of this user interface :)

For sanity, I would be in favor of scoping the issues to links out to a particular site

That makes sense to me too.

jhodgdon’s picture

So. It seems like there are two questions/issues here:

a) For Date/Time formatting, is it possible we could provide either a better UI or some documentation in the page, so that someone could do a custom date format without linking to php.net?

b) In general, we have links in our UI text that go to either drupal.org, php.net, or wikipedia.org (and maybe other places, but I think those three are the most common). We have no standard saying that they should or shouldn't automatically open in a different tab. Should we have a standard about it, and what should it be? Note that we need to consider accessibility and usability both when deciding on this standard. I do not know if target _blank is considered OK for accessibility.

Anyway... I don't know if we should be trying to resolve both of these on this one issue. But it seems like for (b) we need to decide on a standard and then apply it everywhere in Core. For (a) the issue would be just in the date module.

lokapujya’s picture

b.) Please do not make links that open a new browser window. That's what right click->open in new browser is for.

jhodgdon’s picture

I kind of agree with you, but... how do you right click on a phone? I suppose it is something like long-press/choose from options. I don't do much browsing on my phone.

mpdonadio’s picture

#45-a, that page las a lot of options. A lot. I am not sure if we could make it concise enough to be usable for when you have a need for a custom formatter, especially when there are a slew of standard ones.

#45-b, I am hesitant to make an issue about standardizing this. It will win Bikeshed-of-the-Year. But, I think it needs to be done.

jhodgdon’s picture

I think that this particular issue should be just about the Date stuff, and we should open a separate one about _blank in general (even though the title of this one sounds generic, the discussion has mostly been about Date).

mgifford’s picture

Issue tags: +tooltip
Related issues: +#2207383: Create a tooltip component

The accessibility pieces are essentially about user control. Opening up a new page to direct folks to a new page can be disorienting. It's a much better practice to teach users how to use their browser. It's really hard for some users to handle multiple screens (especially on a mobile device) even the browser has good support for them.

Some related resources:
https://css-tricks.com/use-target_blank/
https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Do_not_use_...
http://alistapart.com/article/popuplinks

I wonder if adding a tooltip might be a better pattern here. Just to alert them that this is going outside of their Drupal site.

mpdonadio’s picture

mgifford’s picture

Bojhan’s picture

Issue tags: -Needs usability review
xjm’s picture

Version: 8.1.x-dev » 8.3.x-dev

As a string change, this change would need to be targeted for the development minor, which is currently 8.3.x-dev.

lokapujya’s picture

Reading this again, I think in my comment in #46 that I thought this was generic and maybe didn't realize it was for one specific page. Also, since it's an external page (and we open all external pages on the Babson Portal sites in a new tab), I'm less against it now.

Furthermore, the external page is a reference/help for the opening page.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Issue summary: View changes
Issue tags: -Novice

Remove tag until the

quietone’s picture

Issue summary: View changes
Status: Postponed » Active
quietone’s picture

Title: Target="_blank" attribute add to external links. » Review use of Target="_blank" attribute not in install path
xjm’s picture

Title: Review use of Target="_blank" attribute not in install path » Review (and in most cases remove) use of target="_blank" attribute not in install path
Issue summary: View changes

Interestingly, the original IS requested the opposite of the current scope and accessibility best practice. Updating the IS to avoid confusion.

This is at least wrong in core everywhere the string the documentation for PHP date formats appears, and in the empty text for the frontpage view. And maybe the announcements feed.

xjm’s picture

Title: Review (and in most cases remove) use of target="_blank" attribute not in install path » Review (and in most cases remove) use of target="_blank" attribute outside the installer or update.php

Better scope.

mgifford’s picture

Thanks for updating this @xjm.

We do indeed want to remove the target="_blank" attribute where we can.

xjm’s picture

Tag cleanup. (We don't actually need a11y review right now, and I did the IS update.)

xjm’s picture

I guess whether or not the date format links should open a new window is debatable, because technically they could be on a multistep form. I would still lean toward removing them. We can probably have an accessibility maintainer give feedback on that once we've identified the full scope of what core does.

A novice could work on the next step of this. The next step on the issue is to search for all the uses of target="_blank" in core, and document a list of which category they fall under as I've outlined them in the issue summary. Pay careful attention to the instructions in the issue summary.

neerajsingh’s picture

Issue summary: View changes

Fixed a minor typo in the issue summary.

neerajsingh’s picture

Added a child issue #3541452: Installer and user interactions related target="_blank" in core for

4. For categories 1 and 2, a single child issue should be filed to ensure all the links warn the user that a new window will be opened.

neerajsingh’s picture

Adding the findings around the below categories:

  1. The installer or update.php
  2. Other multistep forms or complex user interactions
Category File path and code
Installer core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php
'#description' => $this->t('When checking for updates, your site automatically sends anonymous information to Drupal.org. See the <a href="@update-status-module-docs" target="_blank">Update Status module documentation</a> for details.', ['@update-status-module-docs' => 'https://www.drupal.org/node/178772']),
Installer core/modules/system/src/Install/Requirements/SystemRequirements.php
'description' => t('PHP OPcode caching can improve your site\'s performance considerably. It is <strong>highly recommended</strong> to have <a href="http://php.net/manual/opcache.installation.php" target="_blank">OPcache</a> installed on your server.'),
Installer core/modules/system/src/Install/Requirements/SystemRequirements.php
'description' => t('PHP APCu caching can improve your site\'s performance considerably. It is <strong>highly recommended</strong> to have <a href="https://www.php.net/manual/apcu.installation.php" target="_blank">APCu</a> installed on your server.'),
Installer core/modules/system/src/Install/Requirements/SystemRequirements.php
'description' => t('This attribute should be explicitly set to Lax, Strict or None. If set to None then the request must be made via HTTPS. See <a href=":url" target="_blank">PHP documentation</a>', [':url' => 'https://www.php.net/manual/en/session.configuration.php#ini.session.cookie-samesite',]),
Multistep forms or user interactions core/modules/migrate_drupal_ui/src/Form/IdConflictForm.php
'#markup' => '<p>' . $this->t('It looks like you have content on your new site which <strong>may be overwritten</strong> ... For more information see the <a target="_blank" href=":id-conflicts-handbook">upgrade handbook</a>.',
Multistep forms or user interactions core/modules/migrate_drupal_ui/src/Form/IdConflictForm.php
'#markup' => '<p>' . $this->t('Possible ID conflicts for translations ... Refer to the <a target="_blank" href=":id-conflicts-handbook">Upgrading Drupal handbook</a> ...',
Multistep forms or user interactions core/modules/views/src/Plugin/views/field/Date.php
'#description' => $this->t('If "Custom", see <a href="https://www.php.net/manual/datetime.format.php#refsect1-datetime.format-parameters" target="_blank">the PHP docs</a> for date formats. ...'),

sanket.tale made their first commit to this issue’s fork.

mradcliffe’s picture

Status: Active » Needs work
Issue tags: +Nara2025, +Needs issue summary update

Thank you for providing a start to this list of usages, @neerajsingh.

I performed Novice Triage on this issue. I am leaving the Novice tag on this issue because I did a review of core and found more instances of target="blank".

This list could be very long as a table and after I asked @xjm we came to a similar conclusion that a concise list format would be better in the issue summary so I added the Needs issue summary update tag.

So the tasks are

  1. Find all the remaining uses of target="_blank" following the instructions in the Remaining tasks section
  2. Update the issue summary and add this list into the Proposed resolution section using a format like
        <h4>Category</h4>
        <ul>
         <li>core/path/to/file:Line Number</li>
       </ul>
      

The Drupal Contribution Mentoring team is triaging issues for DrupalCon Nara 2025, and we are reserving this issue for Mentored Contribution during the event.

After November 19, this issue returns to being open to all. Thanks!

awset’s picture

We are working on it in DrupalCon Nara Contrib Day 2025....

skifdesu’s picture

We are working on it in DrupalCon Nara Contrib Day 2025.

murz’s picture

As we have a lot of occurrences of the target="_blank" - it will be hard to manage in the issue text, I believe.

But I came up with an idea that we can prepare a merge request with the first commit that removes all occurrences of the target="_blank" in all files, and then, step by step, we will make a decision on what to keep and what to revert.

This way should me much more convenient because:
- We will have an actual dynamic list of changes.
- Each changed line will provide an easy way to look on the code around it to understand the context.
- We will be able to comment and discuss each case in a separate thread to make the final decision.

So, we in the Nara contribution room will prepare a merge request with this to start.

xxkiemi’s picture

We are working on it in DrupalCon Nara Contrib Day 2025.

awset’s picture

Prior the MR we worked together to build the consolidated list, we also review each file and assign the category to within the MR.

xxkiemi’s picture

We are working on it in DrupalCon Nara Contrib Day 2025

rduterte’s picture

Status: Needs work » Needs review

I believe @skifdesu, @murz, @xxkiemi, and @awset did a great job reviewing and identifying the files that use the target="_blank" attribute.
I'm updating the issue status to Needs Review.

However, this still needs confirmation because creating an MR may not currently be part of the acceptance criteria. We should also verify whether we actually want to apply these changes before proceeding.

quietone’s picture

Status: Needs review » Needs work

Thanks for identifying the category for each change! Now, to review those, it will actually be better in separate MR's per the remaining tasks in the issue summary. xjm set that up according to the Issue Scope Guidelines, which are to improve things like the quality of the review. It will also separate the category 3 changes which will require input from the accessibility team. Waiting on those discussion should not delay the other categories.

Therefor, setting to needs work for step 3, 4, and 5.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.