1

I use an embed to embed a pdf document:

<embed class="native-pdf" src="https://sample-videos.com/pdf/Sample-pdf-5mb.pdf" type="application/pdf" title="document.pdf" style="width: 100%;>

Now I'd like to detect, whether the embed has been loaded, so I can provide a suitable fallback. However, I can't control the inner content, so I can just peek "from the outside". Here are some values I tried on both (loaded and not loaded):

const embedObj = document.querySelector('.native-pdf')
embedObj.childElementCount // 0 on both
embedObj.hasChildNodes() // false on both
embedObj.style.width // "100%" on both
embedObj.contentWindow // undefined on both
$(embedObj).contents() // undefined on both

Using onloaded does neither fire for both, while $(embedObj).ready() actually fires for both, so I can't distinct between loaded and unloaded.

Background

When the embed is blocked in case of

Failed to load 'https://sample-videos.com/pdf/Sample-pdf-5mb.pdf' as a plugin, because the frame into which the plugin is loading is sandboxed.

then the embed as element still exists but I'd like to automatically fall back to pdf-js (without requiring the user to interact).

Jankapunkt
  • 8,128
  • 4
  • 30
  • 59
  • Have you tried setting the `onload`? [This question](https://stackoverflow.com/questions/740860/load-events-for-embedded-elements) is very old, but seems to imply that works. – DBS Jun 29 '22 at 08:52
  • @DBS sorry for not referring to these, I updated my question accordingly. – Jankapunkt Jun 29 '22 at 09:18

1 Answers1

0

I don't think there is any way the server could detect what the user is doing with their own(ed) materials. object or embed or iFrame should be the same. The PDF is automatically allowed for download so has been downloaded into sandbox, with a default option to view inline or disallowed to run by user choice of settings.

Here as a secured user You are not allowed to run JavaScript in my browsers So PDF will only open in a non JavaScript window and I can naturally modify/edit my html from your site.

enter image description here

K J
  • 8,045
  • 3
  • 14
  • 36