admin管理员组

文章数量:1328568

I have an markup with embed tag want to access #document contents.

Tried to traverse till embed tag after fetching couldn't able to access inner nodes however there is an function available getElementByTagName() or getElementByClassName() but it not helped

var embedContent = document.getElementById('embed1')
var parentContents = x.parentElement.parentNode.lastElementChild.getElementsByTagName('embed')
> [function, embed1: function]

Below able to access embed tag after this how to fetch values of respective tag

Is there alternate way to achieve this??If yes please provide any url or examples.

I have an markup with embed tag want to access #document contents.

Tried to traverse till embed tag after fetching couldn't able to access inner nodes however there is an function available getElementByTagName() or getElementByClassName() but it not helped

var embedContent = document.getElementById('embed1')
var parentContents = x.parentElement.parentNode.lastElementChild.getElementsByTagName('embed')
> [function, embed1: function]

Below able to access embed tag after this how to fetch values of respective tag

Is there alternate way to achieve this??If yes please provide any url or examples.

Share Improve this question asked Apr 25, 2017 at 12:21 rselvaganeshrselvaganesh 1,1222 gold badges18 silver badges31 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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."> </embed>

Your best bet to actually get the HTML is to load that content yourself:

var response = await fetch(document.getElementById('embedTag').src);

本文标签: javascriptHow to access dom elements of document from embed tagStack Overflow