How to set new tab/window on the "link" in phoenix?

I want if some click on my “link” then it should open in a new tab/window. Here is my link-

<%= link("Candidate's Detail", to: Routes.job_open_path(@conn, :show, @job_opening.id), method: :get)%>

Your response will be highly appreciable.

You can add a target: “_blank” option to the link tag, as below ( I splitted it in rows for better visibility)

<%= link("Candidate's Detail",
          to: Routes.job_open_path(@conn, :show, @job_opening.id),
          method: :get,
          target: "_blank") %>

Hth.

4 Likes

Thanks bro.

ur welcome bro :slight_smile:

1 Like

For security reasons, you should also add rel="noopener". To protect user’s privacy you could also add rel="noreferrer". So the full example would be:

<%= link("Candidate's Detail",
          to: Routes.job_open_path(@conn, :show, @job_opening.id),
          method: :get,
          target: "_blank",
          rel: "noopener noreferrer") %>
7 Likes

Thank you @michallepicki. I just learned about the target="_blank" vulnerability, well… better late than ever! :slight_smile:

1 Like

Woow…Great