Discussion:
HTA and new windows
(too old to reply)
Steffen Ramlow
2003-08-20 15:58:15 UTC
Permalink
Hi,

i want to open a new window from one hta with another hta as content. The
problem seems to be that this is impossible without showing the "Open/Save"
dialog, am I right?

Something like this works, when the HTA has the navigable attribute set to
"yes"

<a href="test.hta">show it</a>

This does not work, it shows the "Open/Save" dialog.

<a href="test.hta" target = "Blank">show it</a>

But i really need a new window... :/
Lee
2003-08-20 17:27:48 UTC
Permalink
Post by Steffen Ramlow
Hi,
i want to open a new window from one hta with another hta as content. The
problem seems to be that this is impossible without showing the "Open/Save"
dialog, am I right?
Something like this works, when the HTA has the navigable attribute set to
"yes"
<a href="test.hta">show it</a>
This does not work, it shows the "Open/Save" dialog.
<a href="test.hta" target = "Blank">show it</a>
But i really need a new window... :/
If I recall correctly, opening an "htm" file from an HTA allows it
to run as if it were an HTA, so you should be able to simply change
"test.hta" to "test.htm".
Michael Harris (MVP)
2003-08-20 18:14:05 UTC
Permalink
Post by Lee
If I recall correctly, opening an "htm" file from an HTA allows it
to run as if it were an HTA, so you should be able to simply change
"test.hta" to "test.htm".
Not true for window.open (either explicit or implicit).

True for both window.showModalDialog and showModelessDialog.
--
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
Steffen Ramlow
2003-08-20 19:44:49 UTC
Permalink
Post by Michael Harris (MVP)
Post by Lee
If I recall correctly, opening an "htm" file from an HTA allows it
to run as if it were an HTA, so you should be able to simply change
"test.hta" to "test.htm".
Not true for window.open (either explicit or implicit).
True for both window.showModalDialog and showModelessDialog.
So I have to use these methods and not the open-method when i want to have
new a trusted hta-window?
Is this a bug or does it makes sense?
Michael Harris (MVP)
2003-08-20 22:54:51 UTC
Permalink
Post by Steffen Ramlow
So I have to use these methods and not the open-method when i want to
have new a trusted hta-window?
Yes... Of course, you could also use a WScript.Shell instance and .Run the
other HTA. But if you want to pass information between windows (both ways),
use the dialog method calls.
Post by Steffen Ramlow
Is this a bug or does it makes sense?
AFAIK this behavior is by design, not a bug.
--
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
O Perzia
2003-08-25 21:37:55 UTC
Permalink
From what I can gather in your question, here is a way to
open one hta from another hta.
This assumes there is a second hta file called
Simple2.hta is in the folder.

The # sign in the <a> tag is a blank bookmark (used to
have the link text underlined but not navigate to it).

This method does not prompt the user to Open or Save.

<HTML>
<HEAD>
<HTA:APPLICATION>
<TITLE>HTML Application opens 2nd HTA</TITLE>
// Windows Scripting Host is used to do this

// sample function using VBScript
<script LANGUAGE="vbscript">
Sub runHTA(htaSrc)
Dim WshSHell
set WshShell = CreateObject("WScript.Shell")
WshShell.Run(htaSrc)
End Sub
</script>

//Sample function using JavaScript
<script language=javascript>
function runHTA2(htaSRC2)
{
var winShell = new ActiveXObject("WScript.Shell");
winShell.Run(htaSRC2);
}

</script>

</HEAD>
<BODY>
This is a simple HTML Application.
<a href="#" onClick="runHTA('simple2.hta')">open hta to
hta - vbscript</a>
<p></p>
<a href="#" onClick="runHTA2('simple2.hta')">open hta to
hta - js</a>
<p></p>
<BUTTON onclick="self.close()">Exit</BUTTON>
</BODY>
</HTML>

Let me know if this helps or not.
O. Perzia [MSFT]

Please do not send e-mail directly to this alias. This
alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and
confers no rights.
-----Original Message-----
Post by Michael Harris (MVP)
Post by Steffen Ramlow
So I have to use these methods and not the open-
method when i want to
Post by Michael Harris (MVP)
Post by Steffen Ramlow
have new a trusted hta-window?
Yes... Of course, you could also use a WScript.Shell
instance and
Post by Michael Harris (MVP)
.Run the other HTA. But if you want to pass
information between
Post by Michael Harris (MVP)
windows (both ways), use the dialog method calls.
Post by Steffen Ramlow
Is this a bug or does it makes sense?
AFAIK this behavior is by design, not a bug.
OK, by design, but does it make sense? IMO - no.
.
O. Perzia [MSFT]
2003-08-29 19:15:35 UTC
Permalink
Glad that you have it working. I will try to answer the restrictions
question as best I can. The restrictions occur due to the built in security.
There are 3 methods to open the second hta file: window.open, a link, or
ActiveXObject. The 3 methods use 3 different approaches to opening the hta
file. The window.open and link methods both check if a new application is
opening and prompt the user before opening it for security reasons (there is
no way to disable this check). The ActiveXObject method checks that you are
already in an application and allows a new application to open.
Now if you try to do this from an html page, the first two methods will
still work (as they have a security check) and the 3 one will not work for
security reasons.

Hope this makes some sense,
--
---
O. Perzia [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
Post by O Perzia
set WshShell = CreateObject("WScript.Shell")
WshShell.Run(htaSrc)
Well, this is what i actually do and then hta.commandLine to get the
parameters.
But my question is: why does it not work with the window object or a link,
i
cannot see the sense in this restriction.
Another thing is, that always another mshta.exe is spawn, this is quite
memory consuming.
dknuese
2003-09-04 21:28:07 UTC
Permalink
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?


--
Posted via http://dbforums.com
Walter Zackery
2003-09-06 19:35:55 UTC
Permalink
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
|
Walter Zackery
2003-09-06 20:04:10 UTC
Permalink
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
| |
|
|

Continue reading on narkive:
Loading...