Andrew Poulos said the following on 11/14/2007 10:34 PM:
Randy Webb wrote:
>Andrew Poulos said the following on 11/14/2007 5:57 PM:
>>There's a HTA application that's running on a local computer (not
from a URL) and the user can open a new HTML window by clicking a button
The first time the user clicks the button the window opens. Any
subsequent click causes a dialog, with this error, to appear:
"Error: The remote server machine does not exist or is unavailable"
The relevant code is
oline.onclick = function() {
if (outline.win && outline.win.open && !outline.win.closed) {
outline.win.focus();
} else {
outline.win = window.open(outline.fileName,"", "");
}
};
The MS script debugger claims the error is on the line that starts
"if (outline.win..."
Why does the error occur and how do I resolve it?
My first guess would be that it can't get a proper handle on outline
after it has been opened. Does it happen whether the HTML window is
open or closed or only if it is opened?
The first time you click, the HTML window opens as expected.
If I leave the HTML window open and click the button in the HTA nothing
happens. That is, the HTML window stays behind the HTA though the HTML
window's task bar item flashs.
I made my own test page and I get the same thing except that the first
time I reclick it, it pulls the window up to the front. After that, it
flashes in the taskbar but won't bring it to the front.
If I close the HTML window, the next time I click the button in the HTA
I get the error.
I got the same thing.
If I convert the HTA to a HTML page it runs the HTML window opens
without error in IE, Firefox, and Opera.
I tried wrapping the calls in try catch but it works for one case but
not others. At the moment I'm seeing if always closing the HTML window
in a try catch statement will make a positive difference.
>Aside from that, can you post a URL to a sample .hta file?
Hmm, maybe but I'll have to created a pared down version so my manager
does come done on me.
I got interested and made my own.
This is the script I used in the .hta file:
var newWindow;
function openWindow(){
if (newWindow && newWindow.open && !newWindow.closed) {
newWindow.focus();
} else {
newWindow = window.open('test.html',"", "");
}
}
And the HTML:
<button onclick="openWindow()">Open a Window</button>
test.html was nothing more than a blank test page.
After getting the error and going through the if statement and trying to
narrow down the conditions to see which one was causing the error, I
tried something on a whim and it worked.
The problem seems to be that the HTA can't tell if the window is open or
not when it is closed. So, I set an onbeforeunload in the test.html file:
window.onbeforeunload = function(){window.opener.newWindow = null;}
After adding that to test.html, I never did get another error in the HTA
file.
Two things I did notice though. In an HTA file, if the variable
newWindow didn't exist, it threw an error in the if statement. Meaning,
without the var newWindow; line of code, IE7 was throwing an error on
the if statement. Adding it solved that issue.
Second, and it was more curiosity on my part, but, what is the point in
checking to see if the window is open (outline.win.open) and then
testing to see if it was "not closed" (!outline.win.closed). Seems
perverse to me.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -
http://jibbering.com/faq/index.html
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/