简体   繁体   English

如何访问属于另一个HTML页面的元素ID?

[英]how to access element id which belongs to another html page?

i have a javascript problem 我有一个JavaScript问题

there are three html page like 'page1.html', 'anotherPage.html' and anotherPage.html 一共有三个html页面,例如“ page1.html”,“ anotherPage.html”和anotherPage.html

FOR page1.html 对于page1.html

<div id='mainFrame'></div>

<ul><li onclick="updateFrame(id,"anotherPage.html");"><a href="javascript:;"></a></li></ul>

FOR anotherPage.html 对于anotherPage.html

<ul><li onclick="updateFrame(id,anotherPage2);"><a href="javascript:;"></a></li></ul>

my javascript function: 我的JavaScript函数:

function updateFrame(id,url){
document.getElementById(id).innerHTML="<iframe scrolling='no' style='height:2000px;position:absolute;width:100%;height:100%;left:10px;border-style:none' src=\" "+ url+ "\"></iframe>";} 

The problem is that when i called java script in iframe, javascript did not find the parent document id. 问题是,当我在iframe中调用Java脚本时,javascript找不到父文档ID。 How can i access the parent document id ? 如何访问父文档ID? (Parent document is another html page in this case) (在这种情况下,父文档是另一个html页面)

Thanks. 谢谢。

parent.document.getElementById('myControlId')

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM