gpt4 book ai didi

javascript - 使用javascript在IE9上获取iframe xml内容

转载 作者:行者123 更新时间:2023-12-03 08:17:04 25 4
gpt4 key购买 nike

我很难在 IE9 上获取 iframe 的 xml 内容。在其他浏览器上,它运行良好,但它在 IE9 上的渲染方式是我的问题。

我的 iframe 及其在 IE9 上呈现的内容:

<iframe name="myiframe' id="myiframe">
<Namespace xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Nodes>
<node>
<node>
<Links>
........

我用来获取内容的代码:

var iframe: HTMLIFrameElement = <HTMLIFrameElement>document.getElementById('myiframe');
var xml = iframe.contentWindow.document.firstChild.textContent;

当我尝试 alert xml ,它只显示节点的内容,不包括节点标题,甚至 <> .

我需要 xml 字符串值。有什么想法吗?

最佳答案

实际上,根据您的标记,这是无效的,您已将节点放置在 iframe 的打开/关闭之间,并且仅在任何浏览器不支持 iframe 时才执行。 An example of iframe @MDN

iframe获取文本内容实际上也取决于 Same origin policy .

.textContent 正在做正确的事情来获取您所定位的元素的文本。如果您想获取目标元素的html/Node,那么您应该使用outerHTML:

var xml = iframe.contentWindow.document.firstChild.outerHTML;

关于javascript - 使用javascript在IE9上获取iframe xml内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33887817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com