How to make PDF from GitHub open in new tab?

913 Views Asked by At

I have a pdf file in a GitHub repo and an anchor tag that points to it (<a href="https://github..../file.pdf>link</a>) and when I click it, i download the file automatically.

How to make it open the PDF in a new tab, before downloading it (to the file system, just downloading it within the browser)?

I've tried adding target="_tab" and target="_blank" to the anchor, but all got me the same results?

Is it achieable using just HTML, or I need to use an external JavaScript library?

1

There are 1 best solutions below

1
On BEST ANSWER

You shouldn't need to add target="..." whatsoever. I guess you're pointing to the wrong URL. GitHub provides access to the raw file through this URL pattern:

//github.com/<account>/<repo>/raw/<branch>/path/to/file.pdf

Note the raw part in the URL. Check if you got your URL right. A functional example:

<a href="//github.com/mozilla/pdf.js/raw/master/examples/helloworld/helloworld.pdf">Test PDF</a>

You can test it clicking this link. A dialog will open asking you to specify where to download it.