How to access elements in different frames?

file1.html

<html> <head> <title>AIDS (Automated ID System)</title> <HTA:APPLICATION id="frames" border="thin" caption="yes" icon="http://www.google.com/favicon.ico" showintaskbar="yes" singleinstance="yes" sysmenu="yes" navigable="yes" contextmenu="no" innerborder="no" scroll="auto" scrollflat="yes" selection="yes" windowstate="normal" /> <script language="javascript" type="text/javascript"> function pausecomp(millis) { var date = new Date(); var curDate = null; do { curDate = new Date(); } while(curDate-date < millis); } function getWindowsUserName() { var WinNetwork = new ActiveXObject("WScript.Network"); var urlToSite = createCustomURL(WinNetwork.UserName); var frame = document.getElementById("psyncLink"); frame.onload = function() { frame.onload = null; if (requestingPassword()) { //alert("password button screen"); passwordButtonScreen(); } else { alert("direct password required"); } } frame.src = urlToSite; } function requestingPassword() { var btn = window.frames[1].document.getElementsByName("SUBMIT-password.pss"); if (btn.length == 0) { return false; } else { return true; } } function passwordButtonScreen() { var btn = window.frames[1].document.getElementsByName("SUBMIT-password.pss"); btn[0].click(); } function createCustomURL(userName) { var customURL = "http://localhost/nph-psf.exe?HOSTID=AD&ALIAS=" + userName; return customURL; } function Sleep(milliseconds) { var start = new Date().getTime(); for (var i = 0; i < 1e7; i++) { if ((new Date().getTime() - start) > milliseconds){ break; } } } function whichScreen() { var btn = window.frames[1].document.getElementsByName("SUBMIT-password.pss"); if (btn.length == 0) { alert("no button!"); // User is at password screen var textField = window.frames[1].document.getElementsByName("_MYPW"); textField[0].text = ""; return; } else { btn[0].click(); WaitSeconds(5); var textField = window.frames[1].document.getElementsByName("_MYPW"); textField[0].value = "ios12sdk"; btn = window.frames[1].document.getElementsByName("SUBMIT-VERIFY"); btn[0].click(); } } var loadOtherFrame = function (text) { getWindowsUserName(); alert(text); }; </script> </head> <frameset cols="300px, *"> <frame src="leftframe.html" name="topo" id="topo" application="yes" /> <frame src="topo1.htm" name="psyncLink" id="psyncLink" application="yes" /> </frameset> </html> 

leftframe.html

 <html> <head> <title>AIDS&nbsp;Assistant</title> </head> <script language="javascript"> function checkPassword() { var validString = /^[az](?=[az]*[0-9])[a-z0-9]{0,6}[az]$/; if (validString.test(document.getElementById("newPassword").value)) { alert("The password is valid"); var validate = function () { // validate textbox input ... // call parent page function parent.loadOtherFrame(document.getElementById("newPassword").value); }; } else { alert("The new password does NOT meet the requirements. Please try again."); } } </script> <body> <table width="300px"> <tr> <td>Type Your Old Password</td> <td><input id="oldPassword" type="text" maxlength="8" /></td> </tr> <tr> <td>Please type your new password</td> <td><input id="newPassword" type="text" maxlength="8" min="8" /></td> </tr> <tr> <td colspan="2"><input id="checkOldPassword" type="button" title="Check New Password" value="Check New Password" onclick="checkPassword()" /></td> </tr> </table> </body> </html> 

Let me clarify what I'm doing.

  • leftframe.html need to check text box
  • After processing the left frame. It must notify the parent window file1.html so that it can load the second frame (topo1.htm)

topo.htm does not exist, so the HTA app load cannot be found for this particular frame, but it must change when we call the getWindowsUserName () function from loadOtherFrame. LoadOtherFrame is called from the leftframe.html file, as shown.

When I start the HTA, loadOtherFrame is called (before clicking the button on leftframe.html)

+6
source share
2 answers

Edit to enable text input to the parent page

You can call the function on the parent page from the frame when the text field is checked:

JS IN Leftframe.html

 <script type="text/javascript"> var validate = function () { // validate textbox input ... // call parent page function, passing the text from the input parent.loadOtherFrame(text); }; </script> 

JS in file1.html

 <script type="text/javascript"> var loadOtherFrame = function (text) { // load other frame here ... }; </script> 
+1
source

I assume your frameset no longer in frame . You can access all frames through top.window.frame_name from any frame or top.window .

 form_in_psyncLink=top.window.psyncLink.document.getElementById('form_id'); 

EDIT

If this external page is not in the same domain, you cannot receive its contents in the usual way. Read more about The Same Source Policy for JavaScript . (AFAIK HTA does not change this behavior.)

The above example provides a link to psyncLink , of course, you will use it when checking the script to access the elements in psyncLink to "insert" the data. (which in this case is possibly impossible due to cross pages)

+2
source

Source: https://habr.com/ru/post/918485/


All Articles