# I want my external links to open in a new tab

**URL:** <https://forum.ghost.org/t/i-want-my-external-links-to-open-in-a-new-tab/9830>\
**Category:** Developer help\
**Created:** [October 28, 2019, 8:33pm UTC](https://forum.ghost.org/t/i-want-my-external-links-to-open-in-a-new-tab/9830 "2019-10-28T20:33:37Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![DavidDarnes](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/daviddarnes/32/3533_2.png) [@DavidDarnes](https://forum.ghost.org/u/DavidDarnes)\
**Post date:** [February 5, 2020, 3:02pm UTC](https://forum.ghost.org/t/i-want-my-external-links-to-open-in-a-new-tab/9830/9 "2020-02-05T15:02:56Z")

</div>

I think @jeff’s version expects jQuery to be present, here’s a vanilla JavaScript version:

```js
[...document.querySelectorAll("a[href*='?xgtab&']")].forEach(link => {
	link.setAttribute("target", "moredetail");
});

```

> [@I want my external links to open in a new tab](https://forum.ghost.org/t/i-want-my-external-links-to-open-in-a-new-tab/9830/3):
>
> If you only wanted to do this for specific links, you could simply embed a tag in the href and look for the tag. For example; say I decide to use: ?xgtab& as an indicator to open the page in an [External Giani Tab] open in a new tab: [The domain name newtab.com is available for rent](https://www.newtab.com?xgtab&other=arg&goes=here&etc=etc) open in current tab: [On Site Machining Worldwide | In-Place Machining Company](https://www.inplace.com?other=arg&goes=here&etc=etc) open in a new tab: [https://www.elsewhere.com?xgtab&](https://www.elsewhere.com?xgtab&) and then just use a more advanced selector: $( "a[href\*='?xgtab&']" ).attr("tar…

---

_[View the full topic](https://forum.ghost.org/t/i-want-my-external-links-to-open-in-a-new-tab/9830)._
