Link opening in new tab but also changing origin page to linked page

Hi - I have a weird thing happening. I have a link on an image, and set it to open in a new tab. However, when the link is clicked, it not only brings the user to a new tab to open the link but it also changes the web page where the link was located to that page. For example – we are linking to Bank of America. So when the link is clicked a new tab opens to Bank of America, but our web page also changes to Bank of America. Does anyone know why this is happening and how I can prevent it? (See attached file; I viewed the code in browser and it does “target_blank”???)

Also: I found out how to hyperlink a column or div via discussion here, but have yet to figure out how to have that link open in a new tab. I’ve tried adding “target_blank” but that’s not doing it unless i’m adding it in the wrong place.

Name: onclick
Value (type out don’t paste): location.href=‘https://xxxxxx.com/’;

Thanks in advance for any help!!

Remove the onclick as the image is already wrapped in a link. It’s doing both.

Using the link with href would be better than onclick.

Thanks; but where do I add that? In the custom attributes section or in the header? I tried putting it in custom attributes just as you noted above but it’s still not opening in a new tab…

Currently using custom attributes panel and the following:

Name: onclick
Value: location.href=‘https://website.com/page.html’;

I wasn’t using the onclick with the image link; that one I was doing the normal way in the interactions section; I am only using onclick with the hyperlinks on the columns and divs …

Based on that screen shot the onclick in on the image.

So it’s doing both. Which is why you are getting your page redirect and the new tab.

Hmm now i’m confused. All I did with that one is select the image, go over to “interactions”, input the url and seclect “new tab.” So i’m not sure how to change it.

Remove the onclick from the image.

Select the image and delete the onclick from the custom attribute field on the right panel.

1 Like

Oh my gosh, you are right!! I didn’t even remember putting that there. Deleted it and it works fine. Thanks so much ! Now I just need to figure out how to have the onclick links on my columns open in a new tab…

Currently using custom attributes panel and the following:

Name: onclick
Value: location.href=‘https://website.com/page.html’;

I’d avoid onclick over an actual link if you can. There are ways depending on your design to do this like with .stretched-link

ok thanks I will look into that. but still do not know how to have that element open in a new tab.

Try this …

<a href="https://www.myfancywebsite.com/" target="_blank">Click me</a>

It is just an example of how you might do it using JavaScript…

<a id="myLink">Click me</a>

<script>
  var linkElement = document.getElementById("myLink");
  linkElement.href = "https://www.myfancywebsite.com/";
  linkElement.target = "_blank";
</script>

I hope it helps…