How to Access the Content of the "Embed" Tag in HTML

How to access the content of the embed tag in HTML

Complete about turn!

Turns out you can, see this link: http://xn--dahlstrm-t4a.net/svg/html/get-embedded-svg-document-script.html

(Also, go and up vote some of Erik Dahlström's other answers to give him some points for me hijacking his answer!)

How to access dom elements of #document from embed tag?

The content of an <embed> tag is essentially locked Shadow DOM - it's a whole new document that Chrome can access but you can't.

It's easy to check what properties you can access:

var xObj = document.getElementById('xObj');
for (var p in xObj) { var value = null; try { value = xObj[p]; } catch (err) {}
if (value) console.log(p, value);}
<embed id="xObj" src="http://stackoverflow.com"> </embed>

Get an element in an embed tag

Try

var embed = document.getElementById('myPdf');
// Wait for document to load inside embed element
embed.on('load', function() {
embed.getElementById('next').click();
});

(I am using jQuery in this example for adding the event listener, not sure if you are using it on your project?)

Without jQuery you could do:

var embed = document.getElementById('myPdf');
embed.onload = function() {
embed.getElementById('next').click();
};

It might be possible you can not trigger a click event on that button since a user action often must have taken place to trigger click's from js.

Get element in embed tag

Try this

$(".embeddedObject").find("video").attr("id");

DEMO



Related Topics



Leave a reply



Submit