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

links to social media opening on the same tab #1658

Open
BiliqisO opened this issue Nov 17, 2023 · 1 comment
Open

links to social media opening on the same tab #1658

BiliqisO opened this issue Nov 17, 2023 · 1 comment

Comments

@BiliqisO
Copy link

Opening a link in a new tab or window helps prevent interrupting the user's current flow. This can be useful to ensure that users can easily return to the original page without using the browser's "back" button If a link opens in the same tab, it might cause the user to navigate away from the current page, which may not be the desired behaviour in certain situations.

@0xShankar
Copy link

To prevent social media links from opening in new tabs, you can add the target="_self" attribute to the links. This will tell the browser to open the link in the current tab instead of creating a new one.

Here's an example of how to do this:

<a href="https://www.facebook.com/" target="_self">Facebook</a>

This will open the Facebook link in the same tab as the current page.

You can also use JavaScript to add the target="_self" attribute to all social media links on a page. Here's an example of how to do this:

<script>
  var links = document.getElementsByTagName('a');
  for (var i = 0; i < links.length; i++) {
    if (links[i].href.indexOf('facebook.com') !== -1 || links[i].href.indexOf('twitter.com') !== -1 || links[i].href.indexOf('instagram.com') !== -1) {
      links[i].setAttribute('target', '_self');
    }
  }
</script>

This will add the target="_self" attribute to all links that have the href attribute set to a Facebook, Twitter, or Instagram URL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@BiliqisO @0xShankar and others