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

父页面:

<!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>

效果:
这里写图片描述

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

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

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值