Jump to content

In Markdown, is it possible to open a PDF in new tab?

Recommended Posts

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] &nbsp;&nbsp; [SDS][2]  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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] &nbsp;&nbsp; [SDS][4] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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
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 the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

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

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 the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
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 the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.