miahanson Posted October 29, 2021 Share Posted October 29, 2021 Site URL: https://manatee-squid-rmnx.squarespace.com I have a markdown block on my page https://manatee-squid-rmnx.squarespace.com/data-sheet-selector-2 within my site. There are several drop-downs where the user can choose data sheets for different products. I want the pdf of the data sheet to open in a new tab so that the user doesn't have to go back and forth through the process for additional data sheets. Here is my code: <h3 class="dropdown box">N-100 Fast Dry Series: <span style="color:grey; font-size:.8em;">Designed for smaller presses with fast turn-around times. Also for metering and dampening system rollers</span><span style="text-align:right; float: right;">+</span></h3> <p>[PDS][1] [SDS][2] N-100 Economical, Fast Dry Blanket and Roller Wash</p> [1]: /s/N-100pds-h465.pdf [2]: /s/Nova-N-100-Rev3-SDS-p54d.pdf <p>[PDS][3] [SDS][4] N-103 Economical, Fast Dry Blanket and Roller Wash</p> [3]: /s/N-103pds-5k5g.pdf [4]: /s/Nova-N-103-Rev2-SDS-enk4.pdf My questions: 1. Is using target="_blank" safe to use? I have read that it can be tampered with? 2. Where does that go within Markdown, or do I have to add it to CSS or any other custom code? If there's anyone out there who can help, thank you so much! Link to comment
creedon Posted October 29, 2021 Share Posted October 29, 2021 Site-wide password? Find my contributions useful? Please like, upvote, mark my answer as best , and see my profile. Thanks for your support! Link to comment
miahanson Posted October 29, 2021 Author Share Posted October 29, 2021 Hi Creedon, password is Nova. Thank you so much for your help! Link to comment
creedon Posted October 30, 2021 Share Posted October 30, 2021 Quote 1. Is using target="_blank" safe to use? I have read that it can be tampered with? I'm not sure what you mean by tampering. Tampering by an external entity that will fiddle with your target attribute? If I recall correctly there is software that can prevent target _blank from working as normal. But that is something that the user can install/control so you can't get around that. Quote 2. Where does that go within Markdown, or do I have to add it to CSS or any other custom code? There are two ways you can do this. One is to use Javascript to alter the links in the page to add the target _blank. Two is to use HTML in the markdown. <a href="/s/Nova-SP-99-Rev2-SDS.pdf" target="_blank">PDS</a> Find my contributions useful? Please like, upvote, mark my answer as best , and see my profile. Thanks for your support! Link to comment
miahanson Posted November 1, 2021 Author Share Posted November 1, 2021 Thank you again Creedon. That definitely works, but I would have to recode the entire markdown. If there is more simple Javascript to alter the entire page of PDS and SDS's to open in a new tab, that would be much easier. I have tried a few things like window.open(url, '_blank').focus(); <div onclick="openInNewTab;">SDS</div> and... <script> $('a[href*="pdf"]').click(function(e) { e.preventDefault(); var documentUrl = $(this).attr("href"); // get the url of the pdf window.open(documentUrl, '_blank'); }); </script> within the header code of the page. Can't find the exact code. If you have any suggestions, that would be great. If not, I will alter the markdown code as you suggested. Thank you again! Mia Link to comment
creedon Posted November 1, 2021 Share Posted November 1, 2021 Add the following to Page Settings > Advanced > Page Header Code Injection for the page. <script> /* anchor tag pdfs target attribute _blank add Version : 0.1d0 SS Versions : 7.1, 7.0 By : Thomas Creedon < http://www.tomsWeb.consulting/ > no user serviceable parts below */ window.addEventListener ( 'DOMContentLoaded', ( ) => { const elements = document.querySelectorAll ( '[href$=".pdf"]' ); elements.forEach ( ( element ) => { element.setAttribute ( 'target', '_blank' ); } ); } ); /* end anchor tag pdfs target attribute _blank add */ </script> Let us know how it goes. Find my contributions useful? Please like, upvote, mark my answer as best , and see my profile. Thanks for your support! Link to comment
miahanson Posted November 2, 2021 Author Share Posted November 2, 2021 You are amazing! It works like a charm. Thank you so much Creedon. creedon 1 Link to comment
miahanson Posted November 2, 2021 Author Share Posted November 2, 2021 One last thing, Creedon. Do you have a third-party table generator that you would suggest? My tables will have as many as 30 rows and 10 columns, and I'd like to be able to put links to those same PDF's of the data sheets. Thanks in advance! Link to comment
creedon Posted November 2, 2021 Share Posted November 2, 2021 Quote Do you have a third-party table generator that you would suggest? I have no recommendation for a particular table generator. But a search for html table generator should yield a number of results. Here is one I looked at and it seemed OK at first glance. Tables Generator. Find my contributions useful? Please like, upvote, mark my answer as best , and see my profile. Thanks for your support! Link to comment
miahanson Posted November 2, 2021 Author Share Posted November 2, 2021 Thank you again! creedon 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment