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).