EEX Open URL in New Tab

Hi, I need to redirect from the FrontEnd (EEX) to a new tab with a URL. However these approach don’t work.

Something like this

<a href="" target="_blank">Hola</a>

I have tried the same and also this

<%= link "", to: %>

However I am always redirected to my own domain with a nested redirection. What should I do?

1 Like

How do you set @url? Does it work if you specify the URL literally?

Sorry, I just intended to show as a variable passed from the controller.

Are those quotes missing in your actual code as well?

Please show actual code which fails and also show us how the generated HTML looks like.

<%= link "", to: "" %>


web/controllers/conversion_controller.ex:18: value `""` in `where` cannot be cast to type :id in query:

There are two issues here. Every link without protocol (“http://”, “https://”, …) will be considered a relative url to your current localtion by the browser. Opening the link in an new tab is handled by the target option on the anchor element. For most if not all Phoenix.HTML functions options being passed, which do not have a special meaning to that function, will be used as attribute on the generated html tag.

<%= link "Hola", to: "", target: "_blank" %>

It works!