简体   繁体   English

使用JavaScript在IE9上获取iframe xml内容

[英]Get iframe xml content on IE9 using javascript

I am having a hard time to get the xml content of my iframe on IE9. 我很难在IE9上获取iframe的xml内容。 On other browser, it is working well but the way it rendered on IE9 is my problem. 在其他浏览器上,它运行良好,但是在IE9上呈现的方式是我的问题。

My iframe and it's content rendered on IE9: 我的iframe及其内容在IE9上呈现:

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

The code that I use to get the content: 我用来获取内容的代码:

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

When I tried to alert the xml , it is displaying only the content of the node, not including the node title, even the < and > . 当我尝试alert xml ,它仅显示节点的内容,不包括节点标题,甚至不包括<>

I need the xml string value. 我需要xml字符串值。 Any thoughts? 有什么想法吗?

Actually that is invalid as per your markup, you have put the nodes between the opening/closing of iframe and that only executes if any browser doesn't support iframes. 实际上,按照您的标记,这是无效的,您已将节点置于iframe的打开/关闭之间,并且仅在任何浏览器不支持iframe时才执行。 An example of iframe @MDN iframe @MDN的示例

Also getting text content from iframe is also actually depends on Same origin policy . iframe获取文本内容实际上也取决于“ 同源”策略

.textContent is doing correct thing to get the text of the element you are targeting. .textContent正在做正确的事情来获取您要定位的元素的文本。 If you want to get the html/Node of the element you are targeting then you should use outerHTML : 如果要获取要定位的元素的html/Node ,则应使用outerHTML

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM