2025年window.open 在父页面操纵子页面元素

window.open 在父页面操纵子页面元素父页面 lt DOCTYPE html gt lt html lang en gt lt head gt lt meta charset UTF 8 gt lt title gt Title lt title gt lt

大家好,我是讯享网,很高兴认识大家。

父页面:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script> function showmodelwindow() { 
    var itop = (window.screen.availheight - 510) / 2; //获得窗口的垂直位置; var ileft = (window.screen.availwidth - 650) / 2; //获得窗口的水平位置; var infoWindow = window.open('testopenwindow.html', '', 'height=510px, width=650px, top=' + itop + ',left=' + ileft + ', toolbar=no,menubar=no, scrollbars=yes, resizable=no,location=no, status=no') infoWindow.onload = function() { 
    infoWindow.document.getElementById("test").innerHTML = '2' infoWindow.document.getElementById("tertcc").value="这里是你要赋的值ccccccc"; //表单提交 //infoWindow.document.getElementById('sub_form').submit(); //触发按钮 // infoWindow.document.getElementById("btn").onclick(); } } </script> </head> <body> <input type="button" value="click it" onclick="showmodelwindow()"/> <input type="button" value="c" onclick="confirmback()"> </body> </html> 

讯享网

子页面(子页面也可以是第三方网页,如:实现在自己的页面上操纵第三方页面,实现自动填值,提交的模拟登陆,流程相似):

讯享网<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script> function to_baidu() { 
    window.open('http://www.baidu.com') } </script> </head> <body> <form id="sub_form" method="post" action="http://www.bai.com"> <input type="text" id="tertcc"></input> <input type="button" id="btn" onclick="to_baidu()"></input> <div id="test">1</div> </form> </body> </html> 

效果:
这里写图片描述
讯享网

表单提交效果:
这里写图片描述

触发按钮效果:
这里写图片描述

小讯
上一篇 2025-03-13 12:15
下一篇 2025-04-09 07:14

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/90460.html