如何从embed标签访问#document的dom元素? [英] How to access dom elements of #document from embed tag?

查看:995
本文介绍了如何从embed标签访问#document的dom元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有嵌入标记的标记,希望访问 #document 内容。







还有其他方法可以实现吗?如果是,请提供任何网址或示例。

解决方案

< embed> 标记的内容实际上是锁定的Shadow DOM-这是Chrome可以访问的全新文档



很容易检查您可以访问哪些属性:



  var xObj = document.getElementById('xObj'); for(xObj中的var p){var value = null;尝试{value = xObj [p]; } catch(err){} if(value)console.log(p,value);}  

 < embed id = xObj src = http://stackoverflow.com> < / embed>  



您最好的选择是实际获取HTML是要自己加载该内容:

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


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.

解决方案

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>

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

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

这篇关于如何从embed标签访问#document的dom元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆