Fortunatus Gathot
Fortunatus Gathot

Reputation: 13

open hyperlink in a new tab in PHP

I want to put a download link into a column of my table and use it by a "Download" button.

If somebody clicks the button, a new tab will be opened according to the download link.

My problem is, when I use the code below, it opens a new tab, but instead of going to the link, it adds my website before the real link.

How can I fix this?

<a target="_blank" href=" ('.$row['download'].') "  class="btn btn-sm btn-danger ">
    Download Link
</a>

for example, I put youtube.com, after opening a new tab instead of going to youtube.com, it goes to mywebsite/youtube.com

anybody can help me?

Upvotes: 0

Views: 176

Answers (2)

Ivan
Ivan

Reputation: 40618

I think the problem is that you're using relative paths instead of absolute paths.

So assuming $row['download'] gives you youtube.com for instance. You need to specify in the href attribute of the a tag that it is pointing to another website and not to a page in your website (relative to the page you're on).

I believe you just need to add "http://www." before the name of the website:

<a target="_blank" href="http://www.'.$row['download'].'"  class="btn btn-sm btn-danger ">Download Link</a>

For more information, you can read this article on absolute and relative path links.

Upvotes: 1

Muhammad Zubair Saleem
Muhammad Zubair Saleem

Reputation: 517

You need to specify http:// or https:// before download url

<a target="_blank" href="http://('.$row['download'].') "  class="btn btn-sm btn-danger ">Download Link</a>

Upvotes: 0

Related Questions