Bug: Links inconsistently opening in new tab — remove all target="_blank" site-wide #17

Open
opened 2026-06-29 08:36:08 +00:00 by rob · 1 comment
Owner
No description provided.
rob added this to the eStack Sprint Board project 2026-06-29 09:37:53 +00:00
Author
Owner

Scope: Global — all pages

Description

Links across the site inconsistently open in a new tab. The same link may open in a new tab on one click and in the same tab on a refresh and re-click. This is a race condition from a legacy JavaScript snippet that was added years ago to force new-tab behaviour (per a historical client request). The script isn't always executing before the user clicks, producing the inconsistent behaviour.

The new-tab behaviour is no longer wanted. All navigation should open in the same tab.

Fix

Two-part fix — both needed:

1. Remove target="_blank" from all <a> tags in phtml templates

Search all phtml files for target="_blank" (and any other target attribute values) and remove them.

grep -rn 'target="_blank"' templates-php/

Remove any found instances. Also check for target="_blank" added via PHP string concatenation.


2. Add a global JS safety net in main.js

Add the following to main.js (document ready block) to strip any remaining target attributes at runtime — catches anything set dynamically or missed in the template sweep:

// Remove all target="_blank" — no links should open in a new tab
document.addEventListener('DOMContentLoaded', function () {
  document.querySelectorAll('a[target]').forEach(function (el) {
    el.removeAttribute('target');
  });
});

This runs once on every page load and ensures no link opens a new tab regardless of where the attribute was set.


3. Search for the legacy new-tab JS snippet and remove it

The original script that added target="_blank" to links is likely still in main.js or a legacy JS file. Search for it and remove it entirely — the safety net above is not needed long-term once the source is removed.

grep -rn 'target.*_blank\|_blank.*target' public/js/
grep -rn 'target.*_blank\|_blank.*target' js/

Files to check

File What to check
js/main.js Legacy snippet adding target="_blank" — find and remove; add safety-net snippet above
All templates-php/**/*.phtml Any hardcoded target="_blank" on <a> tags
Any legacy .js files in public/js/ Additional scripts that may be setting target on links

Priority

Medium — affects UX on every page; inconsistent behaviour is confusing

### Scope: Global — all pages ### Description Links across the site inconsistently open in a new tab. The same link may open in a new tab on one click and in the same tab on a refresh and re-click. This is a race condition from a legacy JavaScript snippet that was added years ago to force new-tab behaviour (per a historical client request). The script isn't always executing before the user clicks, producing the inconsistent behaviour. The new-tab behaviour is no longer wanted. All navigation should open in the same tab. ### Fix **Two-part fix — both needed:** **1. Remove `target="_blank"` from all `<a>` tags in phtml templates** Search all phtml files for `target="_blank"` (and any other `target` attribute values) and remove them. ```bash grep -rn 'target="_blank"' templates-php/ ``` Remove any found instances. Also check for `target="_blank"` added via PHP string concatenation. --- **2. Add a global JS safety net in `main.js`** Add the following to `main.js` (document ready block) to strip any remaining `target` attributes at runtime — catches anything set dynamically or missed in the template sweep: ```javascript // Remove all target="_blank" — no links should open in a new tab document.addEventListener('DOMContentLoaded', function () { document.querySelectorAll('a[target]').forEach(function (el) { el.removeAttribute('target'); }); }); ``` This runs once on every page load and ensures no link opens a new tab regardless of where the attribute was set. --- **3. Search for the legacy new-tab JS snippet and remove it** The original script that added `target="_blank"` to links is likely still in `main.js` or a legacy JS file. Search for it and remove it entirely — the safety net above is not needed long-term once the source is removed. ```bash grep -rn 'target.*_blank\|_blank.*target' public/js/ grep -rn 'target.*_blank\|_blank.*target' js/ ``` ### Files to check | File | What to check | |---|---| | `js/main.js` | Legacy snippet adding `target="_blank"` — find and remove; add safety-net snippet above | | All `templates-php/**/*.phtml` | Any hardcoded `target="_blank"` on `<a>` tags | | Any legacy `.js` files in `public/js/` | Additional scripts that may be setting `target` on links | ### Priority Medium — affects UX on every page; inconsistent behaviour is confusing
Sign in to join this conversation.