Cross-browser Access html content of object tag

这一生的挚爱 提交于 2019-12-02 06:44:05

问题


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


回答1:


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 .



来源:https://stackoverflow.com/questions/14435793/cross-browser-access-html-content-of-object-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!