600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > js iframe.contentWindow_iframe页面调用主页面.html

js iframe.contentWindow_iframe页面调用主页面.html

时间:2022-02-14 21:53:55

相关推荐

js iframe.contentWindow_iframe页面调用主页面.html

<!doctype html><html lang="en"><head><meta charset="UTF-8"><title>js iframe</title><script>/*参考:/qq_27626333/article/details/77990196* 知识点:* 在iframe本页面,要操作这个iframe的父页面的DOM元素(即嵌套这个iframe的页面)* 可以用:window.parent、window.top(这里的TOP是获取的顶层,即有多层嵌套iframe的时候使用)* */function parentValue() {/*功能:被 子页面 调用。*/if (confirm('欢迎访问:/qq_27626333')) {location.href = '/qq_27626333'}}</script></head><body><iframe id="myFrame" src='cs3.html' width="510px" height="150px;"></iframe></body></html>

// cs3.html<!doctype html><html lang="en"><head><meta charset="UTF-8"><title>js iframe.contentWindow</title><style>.contain {display: flex;flex-direction: column;/*flex-direction: row;*/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;}</style><script>function parentValue() {/*功能:在子页面中,调用主页面(父页面)的方法。*/window.parent.parentValue();}</script></head><body><div class="contain"><input type='text' id="test" value='欢迎访问:/qq_27626333'><input type="button" id="button" value="调用主页面方法" οnclick="parentValue()"/></div></body></html>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。