window.open 在父頁面操縱子頁面元素
阿新 • • 發佈:2019-02-12
父頁面:
<!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>
效果:
表單提交效果:
觸發按鈕效果: