一般网站做哪些端口映射,wordpress 密码破解,做游戏网站需求确认,东莞手机微信网站1、iframe.contentWindow(主页面调用iframe) 此处的iframe是从document取得的#xff0c;即作作为document的子对象出现#xff0c;虽然是文档(document)对象#xff0c;但由于它是独立的页面#xff0c;因而拥有自己的事件#xff0c;拥有自己的窗口对象(contentWindow)即作作为document的子对象出现虽然是文档(document)对象但由于它是独立的页面因而拥有自己的事件拥有自己的窗口对象(contentWindow)contentWindow属性是指指定的frame或者iframe所在的window对象。 在IE中iframe或者frame的contentWindow属性可以省略但在Firefox中如果要对iframe对象进行编辑则必须指定contentWindow属性。 先获取iframe里面的window对象
var iframe document.getElementById(myFrame).contentWindow// 在IE下
var iframe document.frames[myFrame] 再通过这个对象获取到里面的DOM元素
var input iframe.document.getElementById(test) 在主页面操作iframe里面的DOM元素实例如下
// a.html页面
htmlheadmeta http-equivContent-Type contenttext/html; charsetutf-8titleiframe.contentWindow/titlescript typetext/javascriptfunction getValue() {var tmp ;if(document.frames) {tmp document.frames[myFrame].document.getElementById(test).value;} else {tmp document.getElementById(myFrame).contentWindow.document.getElementById(test).value;}if(confirm(tmp)) {location.href tmp.split(:)[1]}}/script/headbody onloadgetValue()iframe idmyFrame srcb.html width600px height100px;/iframe/body
/html
b.html页面
// b.html页面
htmlheadmeta http-equivContent-Type contenttext/html; charsetutf-8titleiframe/titlestyle#test {border: solid royalblue 2px;border-radius: 4px;width: 500px;color: #797979;height: 50px;line-height: 50px;font-size: 20px;}/style/headbodyinput typetext idtest value欢迎访问http://blog.csdn.net/qq_27626333/body
/html
2、window.parent(iframe页面调用主页面) 在iframe本页面要操作这个iframe的父页面的DOM元素即嵌套这个iframe的页面可以用window.parent、window.top(这里的TOP是获取的顶层即有多层嵌套iframe的时候使用)
// a.html页面
htmlheadmeta http-equivContent-Type contenttext/html; charsetutf-8titleiframe.contentWindow/titlescript typetext/javascriptfunction parentValue() {if(confirm(欢迎访问http://blog.csdn.net/qq_27626333)) {location.href http://blog.csdn.net/qq_27626333}}/script/headbodyiframe idmyFrame srcb.html width510px height150px;/iframe/body
/html
// b.html页面
htmlheadmeta http-equivContent-Type contenttext/html; charsetutf-8titleiframe/titlestyle.contain {display: flex;flex-direction: column;width: 500px;}#test {border: solid royalblue 2px;border-radius: 4px;width: 100%;color: #797979;height: 50px;line-height: 50px;font-size: 20px;}#button {border: solid #20A0FF 2px;border-radius: 4px;margin: 20px auto;padding: 10px;background-color: #20A0FF;color: white;}/stylescriptfunction parentValue() {window.parent.parentValue()}/script/headbodydiv classcontaininput typetext idtest value欢迎访问http://blog.csdn.net/qq_27626333input typebutton idbutton value调用主页面方法 onclickparentValue()//div/body
/html