最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to access dom elements of #document from embed tag? - Stack Overflow

programmeradmin5浏览0评论

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);
发布评论

评论列表(0)

  1. 暂无评论