简体   繁体   English

我可以在JavaScript中获取动态创建的对象标签的contentDocument吗?

[英]Can I get contentDocument of dynamically created object tag in JavaScript?

I load a SVG file from an object tag and access its content from a JavaScript. 我从对象标签加载SVG文件,然后从JavaScript访问其内容。

$(document).ready(function() {
    $(window).load(function () {  
      var a = document.getElementById("svgObj");
      var svgDoc = a.contentDocument;
      // Do something on svgDoc
    });
});

This works fine when I explicitly have a tag in a html page. 当我在html页面中显式包含标签时,此方法效果很好。 When I dynamically create an object tag in JavaScript, "svgDoc" is null and I can seem to get contentDocument of the loaded object tag. 当我在JavaScript中动态创建对象标签时,“ svgDoc”为null,并且似乎可以获取已加载对象标签的contentDocument。 I've tried using the timer to wait until svg file gets loaded but resulted in getting null object. 我尝试使用计时器来等待,直到svg文件被加载,但导致获取空对象。 Is it possible to get "contentDocument" by dynamically creating an object tag and loading svg file on the fly? 通过动态创建对象标签并动态加载svg文件,可以获得“ contentDocument”吗?

http://jsfiddle.net/katakuri/05doayb5/ http://jsfiddle.net/katakuri/05doayb5/

Thanks, katakuri 谢谢katakuri

The problem is CROSS-DOMAIN, 问题是跨域的,

because the SVG file is in other domain 因为SVG文件在其他域中

Get DOM content of cross-domain iframe 获取跨域iframe的DOM内容

暂无
暂无

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

相关问题 如何在jquery中访问动态创建的对象标签的内容? - How can I access the content of a dynamically created object tag in jquery? 我该如何动态添加 <object> 在IE中用JavaScript标记? - How can I dynamically add an <object> tag with JavaScript in IE? JavaScript nullpointer异常:为什么我动态创建的iFrame的contentWindow和contentDocument总是为null? - JavaScript nullpointer exception: Why is contentWindow and contentDocument of my dynamically created iFrame always null? 当我使用javascript从锚标记中单击时,如何获取动态创建的标签的文本 - How do i get the text of a dynamically created label , when i click from anchor tag using javascript 动态创建的javascript对象 - dynamically created javascript object 如何获取具有相同类名且使用Jquery动态创建的span标记值? - How can I get the span tag value which has the same class name and Created dynamically using Jquery? 在 javascript 如何动态获取 object 的嵌套属性 - In javascript how can I dynamically get a nested property of an object 如何在动态创建的选择标记中添加一个空选项? - How can I add an empty option in a select tag created dynamically? 如何在动态创建的元素内插入 span 标签? - How can I insert a span tag inside of a dynamically created element? 如何使用 vanilla JavaScript 从动态创建的输入字段中获取数据? - How can I get data from dynamically created input field using vanilla JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM