Hacker News new | past | comments | ask | show | jobs | submit login

On Chrome/Edge the page seems to open as expected and the PDF is previewed inline. On Firefox, a download immediately starts. Not a big issue or anything, just a slight difference in how browsers handle the page.

The HTML on the page responsible for this:

  <iframe class="pdf" loading="lazy" src="/pdfs/2023-01-24-how-to-lose-fp-at-work.pdf" title="How to Lose Functional Programming at Work - PDF">
  </iframe>
Here's approximately what I've used myself in the past as an alternative:

  <object data="/files/my-document.pdf#zoom=110" type="application/pdf" class="my-style-class" title="My PDF document">
    <!-- Fallback for older browsers that do not support the object tag -->
    <embed src="/files/my-document.pdf#zoom=110" type="application/pdf">
      <!-- Fallback in case PDF display of any sort is not supported -->
      <noembed>
        <span class="my-warning-class">
          It seems like your browser does not support displaying PDF files.
          You can download the file separately <a href="/files/my-document.pdf" download>here</a>.
        </span>
      </noembed>
    </embed>
  </object>
(not too clean of a solution, but seems to work okay in most cases)

The presentation/article itself is pretty nice, though. I really like the mentions of the human aspect of it all, how getting others onboard is quite important!




That's really weird, and I'm sorry that happened. I'm on Firefox Developer Edition on macOS, and it displays inline for me, but that could be my settings.

I'll take a look at using an embed tonight. Thanks for the feedback!


> I'm on Firefox Developer Edition on macOS, and it displays inline for me, but that could be my settings.

I looked into it and it indeed is the settings!

To reproduce the behavior, you'd go to General > Applications, then find PDF and if it's set to "Open in Firefox" then it will render inline, whereas if it's set to any of the other options, then it won't:

  - Open in Firefox: will show the PDF inline, which is probably your setting
  - Always ask: opening the webpage will result in a prompt for what to do with the PDF
  - Save file: will always download it
  - Use OS default application: will download it and then open it
This doesn't seem to be the case with the alternative approach, which just renders it inline always (when the browser in question supports the functionality), though this is definitely a bit of interesting behavior otherwise!


The fix for this is going out right now, and I gave you and your original comment credit in the article. You rock!


I'm doing it wrong! Thanks for looking into this. I will 100% fix this.


well, embedded pdf on iOS looks like a single image of the first page with no ability to scroll or interact in any way, not even select text.

so a text-link outstide of noembed would be a nice alternative anyways, i bet it will be better for screenreaders too


Since this was originally posted, the inline PDF is hidden an replaced with a link on smaller screen sizes.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: