Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect Window Close

Status
Not open for further replies.

vicvirk

Programmer
Feb 4, 2009
636
0
0
CA
I have an exsiting web page with 10,000+ lines of code. We are currently in the middle of re-writting in .net, but for the meantime I need to add some functionality to the existing app within the vbscript (client side).

Here's what I need:

1. User is on abc.html and clicks a link which executes 100 lines of vbscript

2. In the middle of that VBscript code, I need to create a pop up - xyz.html (which is the easy part), have the user make a selection from a drop down list and pass that back to a text box on the parent screen (another easy part) but I need to pause any further execution until that pop-up is closed, or a selection is made (this is where I am stumped).

I do need to run this on the client, so I am unable to use any server-side code - the page cannot refresh.

So far, I've used the following to open the new page:

Sub openWindow(url)
set ie = CreateObject("internetExplorer.application")
ie.width = 450
ie.height = 400
ie.toolbar = false
ie.statusbar = false
ie.navigate url
ie.Visible = True
End Sub

I'm sure I'm not the first to have needed to do something like this, any assistance would be of great help.

Thanks
 
Well, I would break that hundred lines of code further. Put the rest of the execution in a sub. When you popup a new window, do some stuffs, then you close it. On unload event of this popup window, execute the rest of the execution by calling that sub.
 
Yes, I understand what needs to be done, but can't figure out how to do it...

Can you provide a code sample?
 
In your popup window:

<body onunload="callSub()">
 
ok, i see what you mean, but that won't work..

Here's what I am doing:

Code:
1. strReasons = ""
2. for ndx = 1 to 10
3. strThisReason = inputBox("Enter a reason")
4. strReasons = strReasons & strThisReason & ","
5. next
6. raReasons = split(strReasons,",")

do something with each value

The above code, line #4 won't execute until the input box closes from line #3.

Instead of an input box, I need to collect information in a drop down, so I removed line #3 and replaced it with a pop up window that contains a drop down (populated from an external look up list)

Code:
1. strReasons = ""
2. for ndx = 1 to 10
3. pop up window goes here which populated a text box called "tbxReason" on this page.
4. strReasons = strReasons & tbxReason.value& ","
5. next
6. raReasons = split(strReasons,",")

do something with each value

I need to execute line 4 after a value is entered into the textbox (or as soon as the pop up closes). I can't put that into a separate sub as it sits within a for next loop.

The whole thing is within a nested for loop as well (I am looping through rows and columns, with the pop up occuing in the column loop.

 
I thought the script would wait until step3 is done. If you have a msgbox, the next step won't execute until user click OK.
 
It will wait until step 3 is done, so the next step would be step 4.

I need to execute line 4 after a value is entered into the textbox (or as soon as the pop up closes). I can't put that into a separate sub as it sits within a for next loop

I need to get rid of the message box and replace it with a pop up to allow for a drop down box entry.

Instead of an input box, I need to collect information in a drop down, so I removed line #3 and replaced it with a pop up window that contains a drop down (populated from an external look up list)
 
Why don't you move this all to a HTM file? Then you can incorporate the drop down within the same page and use the On Change event to run your code.

Here is a simple sample I created for myself.

Code:
<!--
'==========================================================================
'
' NAME: HotmailOmatic.hta
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' DATE  : 4/21/2006
' (c) 2006 All Rights Reserved
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'
' COMMENT:
'
'==========================================================================
-->
<html>
<head>
<title>HTAOmatic</title>
<HTA:APPLICATION 
     ID="objHTAOmatic" 
     APPLICATIONNAME="HTAOmatic"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="Normal"
>
</head>


<SCRIPT LANGUAGE="VBScript">

Sub Window_Onload
 	RefreshCode = "Pick a selection."
	DataArea.InnerHTML = RefreshCode
	strHTML = "<select style='width: 250' onChange=""CallTextUpdate"" name=FavoriteChooser>" 
    strHTML = strHTML & "<option value= " & Chr(34) & "None" & Chr(34) & ">Select A Color"
    strHTML = strHTML & "<option value= " & chr(34) & "Red" & Chr(34) & ">" & "Red"
    strHTML = strHTML & "<option value= " & chr(34) & "Blue" & Chr(34) & ">" & "Blue"    
    strHTML = strHTML & "<option value= " & chr(34) & "Green" & Chr(34) & ">" & "Green"
    strHTML = strHTML & "</select>"
    dropdownlist.InnerHTML = strHTML
End Sub

Public Function PageRefresh
	Dim WSHShell
	Set WSHShell = CreateObject("wscript.Shell")
	WSHShell.SendKeys "{F5}"
End Function

Public Function CallTextUpdate
	RefreshCode = "<input id=runbutton type='button' value='Refresh Page' name='run_button' onClick='Call PageRefresh'>"
	DataArea.InnerHTML = RefreshCode & "<br>" & "You selected " & FavoriteChooser.Value
End Function




</SCRIPT>


<body style="filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#4B92D9', endColorStr='#CEDFF6', gradientType='0')">
<center>
<table width="100%" height="100%" border="0" cellpadding="0">
<tr><td bgcolor="blue" align="left" height="20" colspan="4">&nbsp;</td></tr>
<tr><td style="filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#CEDFF6', endColorStr='#4B92D9', gradientType='1')" align="left" colspan="4"><img src="[URL unfurl="true"]http://www.thespidersparlor.com/images/tsplogo.jpg"[/URL] align="Right" border="0"><FONT SIZE="+4">&nbsp;HTAOmatic</font></td></tr>
<tr><td style="filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#4B92D9', endColorStr='#CEDFF6', gradientType='1')" align="left" height="5" colspan="4">&nbsp;</td></tr>
<tr>
	<td bgcolor="white" width="5%" rowspan="4">&nbsp;</td>
    <td align="center"><FONT SIZE="+4">Sample HTA</font></td>
    <td bgcolor="white" width="5%" rowspan="4">&nbsp;</td>
</tr>
<tr><td align="center">
	<span id="dropdownlist">&nbsp;</span>
	</td>
	<td align="left" valign="top">
	<p><h3>
	<span id = "DataArea"></SPAN></h3>
	</td>
</tr>
<tr><td align="center">


<br><br><br><br>
Sample HTA by Mark D. MacLachlan<br>markdmac@thespidersparlor.com<br>
</td></tr>
</table>
</center>
</body>

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Maybe I'm making it too complicated, it doesn't seem like something that would be hard to do - I just don't know how it is done (but I'm sure it's possible).

Say I have the following code:

Code:
<html>
<head>
<title></title>
<script language="vbscript">
function yourName() 
names = ""
	for i = 1 to 3
		strName = inputBox("What is the name of month number " & i)
		names = names & " - " & strName
	next
	divName.innerHTML = "You Entered " & names
end function
</script>
</head>
<body>
	<input type="button" onClick="yourName()" value="go" />
	<br /><br />
	<div id="divName"></div>
</body>

How do I duplicate that, but replace the inputBox with a new window that gives a drop down list of options and asks the user to select one of the n number of options available.

It still needs to loop n times (i've just hardcode the number 3)

 
Uh, did you play with what I gave you?

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
I managed to do this in Javascript - I tried converting the syntax to vbscript, but it wouldn't work.

I understand what I was trying to explain may not have made a lot of sense, but if you would like see an example of what I was trying to accomplish, please visit:

(please ignore the markup, it was put together very loosly and then properly implemented within our application)

You can view the source to see what I did and if interested try to duplicate it in VBScript (if you are able to do so, please post your code, i'd love to see it)

Here is the code that I couldn't duplicate in vbscript:

Code:
function checkIfOpen() {
 	// my window is called winRef, opened as follows in a different function:
 	// winRef = window.open('selections.html','selWindow','width=300,height=250,scrollbars=no,directories=no,status=no,menubar=no');

	if (!winRef.closed) {
		wait(1000);
		checkIfOpen();
	} else {
		isOpen = false;
	}
}


function wait(msecs)
{
	var start = new Date().getTime();
	var cur = start
	while(cur - start < msecs)
	{
		cur = new Date().getTime();
	} 
}

markdmac (MIS) 5 Feb 09 18:46
Uh, did you play with what I gave you?

I did (thanks), but I need to create a pop-up, the page is already too crowed...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top