Welcome to WebmasterWorld Guest from 54.197.116.116

Forum Moderators: open

Message Too Old, No Replies

HTA windows

Opening another.

   
12:05 am on Jan 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello. Is there a way to open another HTA window (with all the same customizable options and accessibilities as the original) from the main HTA window? I tried using window.open and it just opens an IE window. Is there any way to fix this? Thanks.

gph

3:45 am on Jan 2, 2006 (gmt 0)

10+ Year Member



function runApp(app){
new ActiveXObject('WScript.Shell').Run(app)
}
runApp('my.hta')
4:58 am on Jan 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks!
2:48 pm on Jan 2, 2006 (gmt 0)

10+ Year Member



I don't know what exactly it is you are trying to do, but I would like to point out that when you open an instance of Internet Explorer as a child window from an HTA using window.open it will inherit the enhanced security privileges of the HTA that launched it.
You can write to the file system and manipulate the operating system in many ways directly from the IE window by calling window.opener and activating functions in the parent HTA. (window.opener.somefunction())

As a basic example, from an HTA, using window.open, you can open an instance of IE full screen in "kiosk" mode whereas from another IE window, for security purposes, you no longer can.
If you check the MS DHTML docs for window.open, it mentions this.

9:50 pm on Jan 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm, well. I would like to open an HTA-customizable window with border controls and such, but still be able to access the opener window properties (window.opener), however when I use the runApp function as posted above, the HTA application cannot access the opener object, presumably since they are considered two different applications.

Any way to fix this?

Thanks. :)

3:48 am on Jan 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I also tried using window.open(), but it does not seem to want to open in its own application instance, rather with Internet Explorer. Any ideas?
4:32 am on Jan 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can probably get round this by launching your own, like this:

var ie = new ActiveXObject("InternetExplorer.application");

You can swap references with the window, and get it to pass back any actions that require priveleges.

Here's a simple example of launching IE. It's done within WSH, so they have the extra ability to add an event handler to the application itself, which you can't do using the ActiveXObject constructor - but you can work around this.

[wsh2.freeweb.hu...]

Here's the documentation for the API:

[msdn.microsoft.com...]

gph

4:49 am on Jan 8, 2006 (gmt 0)

10+ Year Member



You can also communicate between htas on the same computer with cookies or by linking the 2nd hta to a js file them writing the js file with the 1st hta before opening the 2nd.
11:59 pm on Jan 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks! yeah, gph, I tried that, but I need them to communicate more than just one time.

One thing, though: In CreateObject("InternetExplorer.Application"), where do I specify which file to open?

Thanks!

2:03 am on Jan 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah, another problem, unfortunately.

First off, the link you gave me, Bernard, was to a VBScript documentation.

Secondly, I need the instance to be its own application. It can't be suseptible to IE actions, like F1, and CTRL+D. The runApp() code works all except that it cannot communicate with the opener HTA window. Does anybody have a solution?

1:47 am on Jan 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First off, the link you gave me, Bernard, was to a VBScript documentation.

That shouldn't matter too much, adni, sir. Whether we use VB- or JScript for the scripting, the API for the relevant objects, and methodology itself, remain the same. When I first looked at those documents I had only the flimsiest grip on VBScript - and things haven't improved much since then (I largely keep away from it).

You could get round the bookmarking issue by, instead of navigating the new window, innerHTML'ing its content from code stored in a text file or hidden inside a comment in the HTA. Hmm.

It would be nice if HTAs could reference each other by ID or APPLICATIONNAME, but it doesn't seem so.

You might find the answer in showModal/ModelessDialog(). It turns out that windows launched thusly by an HTA are also trusted.

gph

6:14 am on Jan 10, 2006 (gmt 0)

10+ Year Member



You might find the answer in showModal/ModelessDialog(). It turns out that windows launched thusly by an HTA are also trusted.

Good point Bernard. You have more control over those when launched from an hta. The only minor problem is if you keep the window chrome you get the IE logo in the title bar. If that works for adni it should solve the problem.

adni, most, I'd guess around 80%, of MS scripting examples are written in vbs. It's something you'll need to learn a bit about so you can write htas with js.

Once you learn the language a little you'll be able to use vbs and js together. Taking the bests of both languages, which for me means mostly js :)

Here is an example hta that uses js to call some useful/convenient vbs functions. MsgBox in particular is a must have for htas. The functions are simple enough (like my vbs knowledge) to learn the basic language structure.


<html>
<head>
<title>JS & VBS</title>

<hta:application />

<script type="text/jscript" language="jscript">

Date.prototype.vbDate=function(){
return vb_month(this.getMonth()+1,0)+' '+this.getDate()+','+this.getFullYear()
};

onload=function(){
vb_information('my message','');
var chk=vb_confirmWarning(
'Are you sure you want to take this action?','custom title'
);
alert(
'vb_confirmWarning() = '+chk+
'\n\n vb_toCurrency(1000.333) = '+vb_toCurrency(1000.333)+
'\n\nday of year = '+vb_dayOfYear(new Date().vbDate()));
}

</script>

<script type="text/vbs" language="vbscript">

Function vb_information(str,title)
MsgBox str,vbOKOnly + vbInformation + vbApplicationModal,vb_dialogueTitle(title)
End Function

Function vb_confirmWarning(str,title)
vb_confirmWarning = MsgBox(str,vbYesNo + vbCritical + vbDefaultButton2 + vbApplicationModal,vb_dialogueTitle(title)) = vbYes
End Function

Function vb_dialogueTitle(title)
If title = Empty Then
vb_dialogueTitle = document.title
Else
vb_dialogueTitle = title
End If
End Function

Function vb_toCurrency(num)
vb_toCurrency = FormatCurrency(num)
End Function

Function vb_month(num,abbrev)
vb_month = MonthName(num,abbrev)
End Function

Function vb_dayOfYear(date_str)
vb_dayOfYear = DatePart("y",DateValue(date_str))
End Function

</script>
</head>
<body>
</body>
</html>