The same code, commented for better clarity.
Original HTA window ---- hta1.hta
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT type='text/javascript'>
function loadHTA(hta,button)
{
//Open an invisible IE window. The variable is global instead of local
so
//that the IE instance can be closed by any HTA that references it.
self.IE = new ActiveXObject("InternetExplorer.Application");
IE.navigate("about:blank");
while(IE.busy);
//Create a reference to the IE instance's window object.
var win = IE.document.parentWindow;
//This is a crucial step. The window MUST be assigned a name.
win.name = "HTACommWindow";
//Create a reference to the current HTA window from the IE window.
win.htaWindow = self;
//Load the other HTA app.
var shell = new ActiveXObject("WScript.Shell");
shell.run('"' + hta + '"');
button.onclick = function(){};
}
</SCRIPT>
</HEAD>
<BODY>
<BUTTON onclick='loadHTA("hta2.hta",this)'>Load Another HTA App</BUTTON>
</BODY>
</HTML>
Opened HTA window --- hta2.hta
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT type='text/javascript'>
function window.onload()
{
//Use the window.open method to grab a reference to the named window
//created by the 'parent' HTA window. The htaWindow property is a
//reference to the parent HTA window.
self.htaWindow = window.open("","HTACommWindow").htaWindow;
//Close the IE instance created in the parent HTA. It is no longer
needed.
htaWindow.IE.Quit();
//Reference the parent HTA's document object.
var doc = htaWindow.document;
//Do various stuff to the parent HTA document and window.
doc.title = "Title changed by another HTA Window";
doc.bgColor = 'yellow';
htaWindow.focus();
//Create a reference to this HTA from the parent HTA.
htaWindow.htaWindow = self;
//Create a button in the parent HTA that can close this HTA.
var button = doc.body.appendChild(doc.createElement("BUTTON"));
button.value = "Close Other HTA Window";
button.onclick = function(){self.close();}
}
</SCRIPT>
</HEAD>
</HTML>
"Walter Zackery" <***@Newsgroup.com> wrote in message news:***@TK2MSFTNGP10.phx.gbl...
| Michael, I've been playing around with this and I've found a way to have
two
| HTA apps communicate with each other. The trick is to have them both
| reference an open IE window. The IE window can be created using
window.open,
| but I chose to use InternetExplorer.Application to keep the window
invisble.
|
| Original HTA window ---- hta1.hta
|
| <HTML>
| <HEAD>
| <TITLE></TITLE>
| <SCRIPT type='text/javascript'>
| function loadHTA(hta,button)
| {
| self.IE = new ActiveXObject("InternetExplorer.Application");
| IE.navigate("about:blank");
| while(IE.busy);
| var win = IE.document.parentWindow;
| win.name = "HTACommWindow";
| win.htaWindow = self;
| var shell = new ActiveXObject("WScript.Shell");
| shell.run('"' + hta + '"');
| button.onclick = function(){};
| }
| </SCRIPT>
| </HEAD>
| <BODY>
| <BUTTON onclick='loadHTA("hta2.hta",this)'>
| Load Another HTA App</BUTTON>
| </BODY>
| </HTML>
|
| Opened HTA window --- hta2.hta
|
| <HTML>
| <HEAD>
| <TITLE></TITLE>
| <SCRIPT type='text/javascript'>
| function window.onload()
| {
| self.htaWindow = window.open("","HTACommWindow").htaWindow;
| htaWindow.IE.Quit();
| var doc = htaWindow.document;
| doc.title = "Title changed by another HTA Window";
| doc.bgColor = 'yellow';
| htaWindow.focus();
| htaWindow.htaWindow = self;
| var button = doc.body.appendChild(doc.createElement("BUTTON"));
| button.value = "Close Other HTA Window";
| button.onclick = function(){self.close();}
| }
| </SCRIPT>
| </HEAD>
| </HTML>
|
|
| "Michael Harris (MVP)" <***@mvps.org> wrote in message
| news:***@TK2MSFTNGP10.phx.gbl...
| | dknuese wrote:
| | > If opening the second hta via the javascript you show above via the
| | > ActiveXObject, how do I get a reference back to the opened window such
| | > that I can change it's size or location?
| |
| | If you are referring to the example:
| |
| | <script language=javascript>
| | function runHTA2(htaSRC2)
| | {
| | var winShell = new ActiveXObject("WScript.Shell");
| | winShell.Run(htaSRC2);
| | }
| |
| | </script>
| |
| | then the answer is...you can't. See my other replies on this thread.
| | You'll need to open a page with a *.htm (or *.asp, just not *.hta)
| extension
| | using showModelessDialog() which returns a reference to the opened
dialog
| | window.
| |
| |
| | --
| | Michael Harris
| | Microsoft.MVP.Scripting
| |
| | Windows 2000 Scripting Guide
| | Microsoft® Windows®2000 Scripting Guide
| |
http://www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp
| |
| | System Administration Scripting Guide - samples scripts
| | http://www.microsoft.com/downloads/release.asp?ReleaseID=38942
| |
| | WSH 5.6 documentation download
| |
|
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
| |
|
|