# Customized header link target attribute being ignored

**URL:** https://meta.discourse.org/t/customized-header-link-target-attribute-being-ignored/57380
**Category:** Support
**Created:** [February 14, 2017, 7:28pm UTC](https://meta.discourse.org/t/customized-header-link-target-attribute-being-ignored/57380 "2017-02-14T19:28:02Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![greg\_r](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/greg_r/32/121203_2.png) [@greg\_r](https://meta.discourse.org/u/greg_r)
#### Post date: [February 14, 2017, 7:28pm UTC](https://meta.discourse.org/t/customized-header-link-target-attribute-being-ignored/57380/1 "2017-02-14T19:28:02Z")

</div>

I’ve tried a few dozen searches and can’t find an answer to this question so hopefully I haven’t just done a really poor job of searching.

I have customized the header of my Discourse install with a link to another site. That site is on the same domain but different sub-domain (so [blog.example.com](http://blog.example.com) vs [forum.example.com](http://forum.example.com)). I want the link to open in a new tab but no matter what I do it opens in the same tab. If I view the source of the page I can see that the target=“\_blank” is set on the link but it is being ignored. Is there something in Discourse that it overriding the default HTML link behavior? If so, can it be disabled?

I’ve read several topics about the “open external urls” setting in the Admin panel, and have already tried it with both logged in and guest users and it does not work for this link at least. I’d prefer a solution that worked even for guest users. Any help is appreciated.

Thanks

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [February 14, 2017, 7:30pm UTC](https://meta.discourse.org/t/customized-header-link-target-attribute-being-ignored/57380/2 "2017-02-14T19:30:58Z")

</div>

What HTML/Code did you use to create said link in your header? Where did you place that code? Sitepoint has links at the top that utilize `target="_blank"` and it works just fine…

---

<div class="post-metadata">

### Author: ![greg\_r](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/greg_r/32/121203_2.png) [@greg\_r](https://meta.discourse.org/u/greg_r)
#### Post date: [February 14, 2017, 7:50pm UTC](https://meta.discourse.org/t/customized-header-link-target-attribute-being-ignored/57380/3 "2017-02-14T19:50:33Z")

</div>

Here is the code I used:

```
<script type="text/discourse-plugin" version="0.4">
api.decorateWidget('home-logo:after', helper => {
    const showExtraInfo = helper.attrs.minimized;
        if(!showExtraInfo) {
            return helper.h('a.blog-link', {href:'https://blog.example.com', target:'_blank'}, 'Visit our blog');
        }
});
</script>

```

I placed that in the Customize → CSS/HTML → `</head>` section. Running 1.8.0 beta4 (upgrading to beta5 to see if it helps).

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [February 14, 2017, 7:58pm UTC](https://meta.discourse.org/t/customized-header-link-target-attribute-being-ignored/57380/4 "2017-02-14T19:58:07Z")

</div>

@eviltrout, this seems like a legitimate issue. Doesn’t apply to SP, because we use a different technique. But it is happening at Feverbee too, which I know are using a similar (if not the same) technique as described here.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [February 14, 2017, 8:31pm UTC](https://meta.discourse.org/t/customized-header-link-target-attribute-being-ignored/57380/5 "2017-02-14T20:31:34Z")

</div>

Is the click being intercepted?

[https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/widgets/home-logo.js.es6#L49-L55](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/widgets/home-logo.js.es6#L49-L55)

[https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/lib/intercept-click.js.es6#L3-L5](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/lib/intercept-click.js.es6#L3-L5)

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [February 14, 2017, 9:13pm UTC](https://meta.discourse.org/t/customized-header-link-target-attribute-being-ignored/57380/6 "2017-02-14T21:13:01Z")

</div>

> [@Mittineague](#):
>
> Is the click being intercepted?

Not sure, I may try debugging it later, but I was fairly certain it worked at Feverbee previously so I think this is a regression of some sort, but not sure why or where.

**Edited:**  
So I did debug it, and maybe this never worked, though I could have sworn it did. But I don’t see anything obvious that is set to handle `target="_blank"`, but it is definitely being intercepted by intercept-click.js.es6

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [February 14, 2017, 11:23pm UTC](https://meta.discourse.org/t/customized-header-link-target-attribute-being-ignored/57380/7 "2017-02-14T23:23:35Z")

</div>

Oh this is interesting, if you take that code and change it to

```plaintext
<script type="text/discourse-plugin" version="0.4">
api.decorateWidget('header-buttons:after', helper => {
    const showExtraInfo = helper.attrs.minimized;
        if(!showExtraInfo) {
            return helper.h('a.blog-link', {href:'https://blog.example.com', target:'_blank'}, 'Visit our blog');
        }
});
</script>

```

It will open in a new window just fine.

So there seems to be a difference in how the clicks are handled when it is `home-logo:after` versus `header-buttons:after`

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [February 17, 2017, 9:28pm UTC](https://meta.discourse.org/t/customized-header-link-target-attribute-being-ignored/57380/8 "2017-02-17T21:28:05Z")

</div>

Yeah the home-logo has special click handling:

[https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/widgets/home-logo.js.es6#L49-L55](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/widgets/home-logo.js.es6#L49-L55)

We’ve gone over it many times to make sure the logo works the way people expect, but I guess it means it’s a bit weird if you add more formatting to it. I think it’s probably best if the link is placed elsewhere, like in @cpradio’s example.

---

<div class="post-metadata">

### Author: ![greg\_r](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/greg_r/32/121203_2.png) [@greg\_r](https://meta.discourse.org/u/greg_r)
#### Post date: [February 17, 2017, 10:06pm UTC](https://meta.discourse.org/t/customized-header-link-target-attribute-being-ignored/57380/9 "2017-02-17T22:06:12Z")

</div>

Thanks @cpradio and @eviltrout for the feedback. I’ve moved the code into the header-buttons area – not ideal but it gets the job done. It might be nice if there was a class or something you could apply to a link to override Discourse hijacking the link target. It certainly is confusing when you click on a link and it doesn’t behave in the standard way.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [February 17, 2017, 11:12pm UTC](https://meta.discourse.org/t/customized-header-link-target-attribute-being-ignored/57380/10 "2017-02-17T23:12:19Z")

</div>


