Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added open-external-links.js to open external links in new tab #7540

Conversation

rahulmansharamani14
Copy link

Summary

This PR ensures that all external links in the Mattermost documentation open in a new tab or window, addressing Issue #7048.

Changes Made

  • Added open-external-links.js:

    • Located in the _static/js directory.
    • Contains JavaScript code that adds target="_blank" to all external links.
  • Updated conf.py:

    • Added open-external-links.js in the html_js_files list to include this file in the build process.

Implementation Details

  • The script selects all <a> elements and checks if they have the external class.
  • External links are modified to include target="_blank", opening them in a new tab/window.

Testing

  • Built the documentation locally using make clean build.
  • Verified that:
    • External links open in a new tab/window.
    • Internal links open in the same tab/window.
  • Tested across multiple pages.

Notes

  • This solution depends on external links being assigned the external class by Sphinx during the build process.
  • No additional dependencies are introduced.
  • No changes to existing content or functionality other than modifying external link behavior.

Thank you for reviewing my PR. I'm open to any feedback or suggestions.

Ticket Link

Fixes #7048

@mattermost-build
Copy link
Contributor

Hello @rahulmansharamani14,

Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here.

@cwarnermm cwarnermm self-requested a review November 4, 2024 14:12
@cwarnermm cwarnermm added 2: Editor Review Requires review by an editor preview-environment Allow the preview environment to be generated for Pull Requests coming from fork repositories labels Nov 4, 2024
Copy link

github-actions bot commented Nov 4, 2024

Newest code from rahulmansharamani14 has been published to preview environment for Git SHA 985b96e

@cwarnermm
Copy link
Member

@rahulmansharamani14 - It looks like all links are opening in new browser windows right now, rather than only external links.

@cwarnermm cwarnermm added the Awaiting Submitter Action Blocked on the author label Nov 5, 2024
@rahulmansharamani14
Copy link
Author

Hi @cwarnermm, Thank you for reviewing my PR and for your feedback.

I wanted to clarify that, based on my testing, internal links are opening in the same tab, while external links are opening in new tabs, which is the intended behavior.

Testing Details:

  • Environment: I built the documentation locally using make html and served it using a local server at http://127.0.0.1:8000/.
  • Internal Links: Links that point to the local domain (e.g: http://127.0.0.1:8000/some-page) open in the same tab.
  • External Links: Links that point to external domains (e.g: https://mattermost.com) and have class="external" open in a new tab/window.
    Examples:

Internal Link:

URL: http://127.0.0.1:8000/developer/contribution-guide.html
Behavior: Opens in the same tab.

Screenshot:

Screenshot 2024-11-08 at 5 30 59 AM

External Link:

URL: https://github.com/mattermost/mattermost-server
Behavior: Opens in a new tab/window.

Screenshot:

Screenshot 2024-11-08 at 5 31 24 AM

Possible Reasons for Different Behavior:

  • Server Environment: Perhaps the difference arises if the documentation is viewed in a different environment or after deployment.
  • Cache or Browser Extensions: Sometimes, cached files or browser extensions can affect link behaviors.

Could you please let me know if there's a specific page or link where you're seeing all links opening in new tabs? I'd be happy to investigate further. If there's a particular environment or method you're using to build and serve the documentation, please share the details so I can replicate it.

@cwarnermm
Copy link
Member

cwarnermm commented Nov 8, 2024

@rahulmansharamani14 - There's a generated preview of the product docs that uses the code in this docs PR. In that preview environment (which mirrors production), I'm continuing to see links to pages of the product docs that open in a new browser window.

Examples include:

I haven't done an exhaustive search; however, a common pattern I'm seeing here is mid-page links (that should take the user to another section of the current document) opens a new browser tab.

@cwarnermm
Copy link
Member

@rahulmansharamani14 - Are you open to addressing the outstanding issues on this docs PR?

@mattermost-build
Copy link
Contributor

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

@cwarnermm
Copy link
Member

Closing due to inactivity.

@cwarnermm cwarnermm closed this Nov 28, 2024
@mattermost-build mattermost-build removed the Awaiting Submitter Action Blocked on the author label Nov 28, 2024
@amyblais amyblais removed the 2: Editor Review Requires review by an editor label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Contributor Lifecycle/1:stale preview-environment Allow the preview environment to be generated for Pull Requests coming from fork repositories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Open all external links in a new tab/window
4 participants