如果 page2 包含指定元素,我需要更改 page1 的内容。如果我从同一页面获取 id,此代码效果很好
if (document.getElementById("page_element")) {
var str = document.getElementById("destination").innerHTML;
var n = str.replace("Login", "Logout");
document.getElementById("destination").innerHTML = n;
}
但我需要检查第 2 页上是否存在元素才能更改第 1 页的内容。
我必须改变这个
if (document.getElementById("page1_element"))
正确的路径是page2(在我的例子中是logged.html)。我怎样才能做到这一点 ?
认为这会起作用...
var iframe = document.getElementById("iframeId"),
doc = getFrameDocument(iframe);
doc.getElementById("page2_element_id"); // [DOM Element]
function getFrameDocument(iframe){
return iframe.contentDocument ? iframe.contentDocument : iframe.contentWindow.document;
}
return cond ? a : b
means:
if ( cond ) {
return a;
}
else {
return b;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)