访问对象标签的外部HTML页面内容

访问对象标签的外部HTML页面内容

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

问题描述

我已经搜索了这个问题的答案,但无法找到一个方法。

I've searched an answer to this question but can't get a way how to do it.

我想访问一个div的内容,我已经包含在一个对象标签中。

I want to access the content of a div that I have included in an object tag.

我的include.htm文件:

My include.htm file:

<div id="includedDiv">This is the included page</div>

我尝试过:

<html>
<head>
<title>Get element from object included page</title>
</head>
<body>
<p>Test: This is the main page</p>
<object id="obj" data="include.htm"></object>
<script>
//alert(document.getElementById("includedDiv").firstChild.nodeValue);
//alert((document.getElementById("obj")).document.getElementById("includedDiv").firstChild.nodeValue);
alert(document.getElementById("obj")["includedDiv"]);
</script>
</body>
</html>

没有一个警告打印出我的消息这是包含的页面,有没有办法从DOM获取此内容?

None of the alert prints me the message "This is the included page", is there a way to get this content from the DOM?

编辑:
window [0] .document.getElementById(includedDiv)。firstChild.nodeValue;是通过DOM访问的好答案,对象标签只是创建另一个窗口:)

推荐答案

更好的答案:你可以通过DOM访问对象标签内容,它只是另一个窗口!

Even better answer: you CAN access object tag content through the DOM, it is just another window!

window[0].document.getElementById("includedDiv").firstChild.nodeValue;

就是这样:D

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

07-27 14:53