I have a URL that comes to me from the backend. When I open this URL a pdf is loaded automatically. I don't want the pdf to be loaded automatically. I want to open the pdf at that URL in a new tab when I click a button. How can I do this in React?
CodePudding user response:
Just create a component that renders this, maybe pass the link through properties
const PDFLink = props => (
<a href={props.link} target="_blank">
Link to PDF
</a>
);
CodePudding user response:
You can use a special _blank
parameter/attribute for it:
window.open("pdf_url", '_blank');
When you use an <a>
anchor tag with link in your code:
<a href="pdf_url" target="_blank">Open</a>