跨浏览器访问对象标签的html内容

跨浏览器访问对象标签的html内容

本文介绍了跨浏览器访问对象标签的html内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 object 标签,其数据属性来自同一个域的html文件。



访问html的内容。



HTML:

  object id =objectwidth =420height =360data =jsp / index.html>< / object> 

JS:

  var object = document.getElementById(object)。contentDocument; 
var html = object.getElementById(tmpl)。innerHTML

除了 IE7



,请帮助我访问对象的DOM内容 我发现了一些重要的事情,首先是:



1>我第一次尝试得到html的内容像firebug:

  console.log(document.getElementById(iframe)。contentDocument.innerHTML); 

我要在这里附上我的firebug结果:



>





2>同样,我也试过了对象,这也是我得到的:



>



从这里很明显,它是失败,因为



我不知道你是如何访问他们的,为我这个域和主机不可访问。这是猜测,也是你未能获取对象id的内容的原因。我建议您使用 以在此处完成操作。


I have object tag with a data attribute to a html file from same domain.

I want to access the content of the html.

HTML:

<object id="object" width="420" height="360" data="jsp/index.html"></object>

JS:

var object = document.getElementById("object").contentDocument;
var html = object.getElementById("tmpl").innerHTML

The above code is working in all browsers except IE7

Please help me in accessing the DOM content of object tag in IE7

解决方案

Ok so i tried to play around the code a little as provided by you and i found out some important things, first of which is:

1> I first tried to get the contents of html like this in firebug :

console.log(document.getElementById("iframe").contentDocument.innerHTML);

I am gonna attach my firebug result here :

So you can see that there is a permission denied coming up here.

2> Similarly, i tried out for object also and this is what i got :

From here it is fairly evident that it is failing because of the Same Origin Policy.

I do not know how you are accessing them, but for me this domain and host in not accessible. This is guess, is also the reason for you failing to get the contents of the object id . I suggest that you use Cross-site HTTP requests or the CORS way to get things done here .

这篇关于跨浏览器访问对象标签的html内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 22:39