# Open internal links in same browser tab

**URL:** https://meta.discourse.org/t/open-internal-links-in-same-browser-tab/172353
**Category:** Support
**Created:** [December 5, 2020, 11:01pm UTC](https://meta.discourse.org/t/open-internal-links-in-same-browser-tab/172353 "2020-12-05T23:01:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)
#### Post date: [December 5, 2020, 11:01pm UTC](https://meta.discourse.org/t/open-internal-links-in-same-browser-tab/172353/1 "2020-12-05T23:01:34Z")

</div>

Many of us put discourse in a subdomain and also have a site in the root, eg, [meta.discourse.org](http://meta.discourse.org) and [discourse.org](http://discourse.org). However when the global setting of `default other external links in new tab` is set to `Open external links in a new tab by default` it assumes all non-forum links are external - is there any way to add domains so that they open in the same browser tab? (If not, could this option be added please?)

There is an `allowed internal hosts` setting, with desc: `A list of internal hosts that discourse can safely crawl for oneboxing and other purposes` - maybe simply use this and domains added here could set them to open in the same tab?

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [December 6, 2020, 4:19am UTC](https://meta.discourse.org/t/open-internal-links-in-same-browser-tab/172353/2 "2020-12-06T04:19:20Z")

</div>

This sounds like a very specific need, so your best bet is doing it via theme/plugin.

---

<div class="post-metadata">

### Author: ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)
#### Post date: [January 6, 2021, 3:15pm UTC](https://meta.discourse.org/t/open-internal-links-in-same-browser-tab/172353/3 "2021-01-06T15:15:01Z")

</div>

I’d want to do this on every Discourse instance I run tbh Rafael, I can’t see why anyone wouldn’t want to do it - if a site is the same internal/parent domain you’d probably want the link to open in the same window. I wonder if it’s worth putting up a poll for things like this to get a feel for what people using Discourse might prefer? I think you might be surprised by the results 😊

---

<div class="post-metadata">

### Author: ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)
#### Post date: [February 17, 2021, 12:22am UTC](https://meta.discourse.org/t/open-internal-links-in-same-browser-tab/172353/4 "2021-02-17T00:22:55Z")

</div>

What’s the best way to do this Rafael?

I tried using:

```plaintext
<script type="text/discourse-plugin" version="0.8.42">
	api.decorateCookedElement(
	  element => {
	    const tags = element.querySelectorAll('.hashtag');

	    tags.forEach(function(tag) {
				if (tag.hasAttribute('href')) {
					if (tag.href.includes("site.com/tag/")) {
						tag.href = tag.href.replace("site.com/tag/", "newsite.com/")
						tag.setAttribute("target", "_self");
					}
				}
	    });
    },
	  {
	    onlyStream: true
	  }
	);
</script>

```

and while:

```plaintext
tag.setAttribute("target", "_self");

```

sets the attribute it doesn’t not have any impact, with links opening in a new tab as normal.

I guess I need to use something other than `api.decorateCookedElement`?
