File download, button and text, target="_blank"
-
I want to have a downloadable pdf with text and a button.
I choose to insert the block “File” and upload a pdf-file. Set the option Open in new tab.The “text-link” opens the pdf in a new tab but the button opens the pdf in the same tab. When I look at the HTML I can see that taget=”_blank” is set on the text but not on the buttons. Strange.
When I try to add target=”_blank” to the button it says that the block has crashed…Why does the the text-link and the button have different behaviour?
-
Hi there,
Can you give a link to the site you’re working on, and to the specific post/page where you’ve added this content, so we can take a look?
-
-
Thanks.
It looks like this is indeed by design, that the target doesn’t apply to the button. That’s because when you click on the button, the file is supposed to just download in the background without any changes at all happening in the browser window. If you look carefully at the HTML, you’ll see the
downloadattribute added in the `<a> tag for the button. That instructs the browser to just download the file.But most browsers these days have a PDF reader built in, and if the default in your browser is to open PDF links in that built-in reader rather than downloading the file, clicking the button will cause the file to open rather than download, and that then happens in the same tab, as the button was never intended to open a new tab in the first place.
If I disable the built-in PDF reader in my browser, it works the way you want, just downloading the files if you click the button. That’s also how it works for me if I test this with any non-PDF file.
So this is a case of the browser overriding the
downloadattribute in the<a>tag, and likely isn’t something we’ll be able to change.<blockquote> When I try to add target=”_blank” to the button it says that the block has crashed…</blockquote>
That’s because the button code doesn’t expect that attribute to be added. But if you go ahead and save/update the post with that error there, the
targetattribute will actually get added, and it will work the way you want. It’s just a case of the editor not knowing how to treat the unexpected attribute. -
Thank you for the answer and your time.
The suggested solution works on front end but is not so pretty “back stage”. And since there is someone else who will edit this pages I can not have it look like there is something wrong with that block.
(I am used to WordPress.org things of doing things….)
- The topic ‘File download, button and text, target="_blank"’ is closed to new replies.