在这里,我构建了一个带有iFrame
的HTML页面。我在iFrame
src页面中有一个id。是否可以通过JavaScript从我当前页面访问id。
请帮帮我。
答案 0 :(得分:1)
如果您从父页面访问iframe的脚本,请务必小心,以确保您的iframe在请求之前已经完成加载。这是一个例子:
window.onload = function () {
document.getElementById('iframeId').onload = function () { //Attach an onload function to the iframe
//Do the stuff you want to do with the iframe here
//because this function is executed once the iframe has finished loading
};
};
答案 1 :(得分:0)
这是我通过的一个小例子,
<title>Untitled Page</title>
<script type="text/javascript" >
function ShowVal() {
alert(myIframe.document.getElementById('nameText').value);
}
</script>
'myIfrmae'是iframe的ID。 'nameText'是iframe中包含的页面中的文本框控件。
我在单击按钮时从父页面调用此ShowVal函数。
感谢。
P.S。抱歉无法发布整个示例。发布Html时遇到问题。