How can i make an HTA window dependent on another? - hta

I need to make an .hta window dependent on the other .hta window. So, basically window A cannot be closed without window B being close first. I have the two window right next to each other and they act as one window when settings is click (it basically displays a popout or extension of the first window that has options for the application).
Second window is executed by:
Sub Settings()
Set objShell = CreateObject("WScript.Shell")
objShell.Run "Launcher-Settings.hta"
End Sub
And the button is:
<input type="button" value="Settings" name="MSG-Button" id="LauncherSettings1" class="LauncherSetting1" onClick="Settings()" />
Both windows are close by:
<input type="button" value="<< Close" name="CloseButton" id="CloseButton" class="CloseButton" onClick="javascript:Window.close()" />

There's a typo in my comment, it should be "unload events are not cancelable...".
You can force window B to be closed just before closing A using WMI, something like this:
top.onbeforeunload = function () {
var wmiLocator = new ActiveXObject('WbemScripting.SWbemLocator'),
wmiService = wmiLocator.ConnectServer('.', 'root\\CIMV2'),
htaProcesses = new Enumerator(wmiService.ExecQuery("Select * from Win32_Process Where name = 'mshta.exe'")),
htas = [], n;
while (!htaProcesses.atEnd()) {
if (htaProcesses.item().CommandLine.indexOf('Launcher-Settings.hta') > -1) {
htas.push(htaProcesses.item());
}
htaProcesses.moveNext();
}
for (n = 0; n < htas.length; n++) {
htas[n].Terminate();
}
return;
}

Related

Opened multiple popup using window.open().How to make all popup stay at top and also access parent page

I have a scenario where I need to open multiple popup almost 5 . If I use window.open() method , I can open multiple popups but it is not staying on top of parent page all the time. After I open first popup , it shows on top of parent page. then when I access parent page to open second popup , first popup goes behind the parent page. Is there any way I can achieve this functionality.
Any help greatly appreciated
One way is to store the window handles in an array and call the focus method. It works in IE. It will not work in Chrome, details here
FIDDLE
Code below.
var popupWindowsArr = new Array();
function popupClicked() {
var title = "Test -" + popupWindowsArr.length;
var wndID = window.open("http://www.google.com", title, "height=400,width=700");
popupWindowsArr.push(wndID);
for(var i = 0; i < popupWindowsArr.length; i++) {
popupWindowsArr[i].focus();
}
}
EDIT - To bring focus to popups after a postback.
One way is store the names of the opened windows in a hidden field and use it. This will work only if the popup url is in the same domain.
<asp:HiddenField ID="hdnPopupNames" runat="server" />
function popupClicked() {
var popupNames = document.getElementById('<%=hdnPopupNames.ClientID %>').value;
var wndName;
if (popupNames.length > 0) {
var namesArr = popupNames.split("|");
wndName = "Test -" + namesArr.length;
for (var i = 0; i < namesArr.length; i++) {
var wnd = window.open("", namesArr[i]);
wnd.focus();
}
popupNames += "|" + wndName;
}
else {
wndName = "Test - 0" ;
popupNames = wndName;
}
window.open("TestHTMLPage.htm", wndName, "height=400,width=700");
document.getElementById('<%=hdnPopupNames.ClientID %>').value = popupNames;
}

Mouse middle button does not work

i have a gridview which contains a linkbutton with a ID LnkCourseName
i have requirement that on a click of Middle button of a mouse a new tab should open.
to check the which button of a mouse got clicked, i used a javascript function as :
<script type="text/javascript">
function buttonalert(event) {
var button;
if (event.which == null)
button = (event.button < 2) ? leftclickclear() :
((event.button == 4) ? middleclickclear() : rightclickclear());
else
button = (event.which < 2) ? leftclickclear() :
((event.which == 2) ? middleclickclear() : rightclickclear());
dont(event);
}
function leftclickclear() {
$('#<%=HdUrl.ClientID %>').val("left");
}
function rightclickclear() {
$('#<%=HdUrl.ClientID %>').val("right");
}
function middleclickclear() {
$('#<%=HdUrl.ClientID %>').val("middle");
}
function dont(event) {
if (event.preventDefault)
event.preventDefault();
else
event.returnValue = false;
}
</script>
But on a press of a middle button i get an error
javascript:__doPostBack('dnn$ctr538$ViewTC_TakeAClass$GrdCourseDetail$ctl02$LnkCourseName','')
on a new tab url. Thanks for assistance.
This should be standard behaviour for any reasonable browser, and isn't really an ASP.NET or script issue - the problem is that you're using a link button, which will do a postback just like a button (i.e. <input type=submit>), and it's not a link as in an default a element.
If your links are really just that, and are not expected to post back to the server to execute some logic, and instead just specifies a URL to link to, then use a HyperLink control instead.

Flex: How to determine if a PopUpManager window is open (or when it has closed)?

In Flex (Flash Builder 4) I am opening a new window via PopUpManager.addPopUp. I have timer code that runs in my component and I need to stop my timer when that window opens and start the timer again when the window closes.
I figure it's easy enough to stop the timer in the function that opens the window, but how can I start the timer again when the window closes?
Is there a way to tell if there is a pop-up window in front of my component, or if a specific pop-up window is still open via PopUpManager?
Maybe events are a better approach?
Thanks!
Events! is the way to go.
Fire events during launch/close. Add your logic in the event Handlers!
You can use following code to check whether opened popup window is getting closed or not.
if it is closed you can stop the timer.
//set the flag to find your popup window is exist or not.
private var isPopupExist:Boolean = false;
private function closePopUpWindow():void
{
var systemManager:SystemManager = FlexGlobals.topLevelApplication.systemManager;
//Returns a list of all children.
var childList:IChildList = systemManager.rawChildren;
for(var i:int=childList.numChildren-1;i>=0;i--)
{
var childObject:* = childList.getChildAt(i);
//If child object is Uicomponent.
if (childObject is UIComponent)
{
var uiComponent:UIComponent = childObject as UIComponent;
//If uicomponent is popup and class name is equal to **your popup component name** here i am using "ChatComp".
if (uiComponent.isPopUp && uiComponent.className == "ChatComp")
{
isPopupExist = true;
}
}
}
}
in your Timer,
private function checkPopUpExistance():void
{
call closePopUpWindow() function for every 1 sec or any seconds(your wish) to check whether popup is exist or not.
if(isPopupExist)
{
here you stop the timer.
}
}
Now you can start the Timer, when you opened the Popup window.
The popupmanager is a singleton class, so you can easily know how many popups have been created with his ChildList
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/managers/PopUpManagerChildList.html

Update HiddenFiled value on parent window after child window is close Javascript,VS2005 c#

I have a child window and a parent window with a hiddenfield hdnSelectedFields .I am changing the value of hdnSelectedFields.
Code:
String vStrScript = "<script language=javascript>function CloseParent() {window.opener.document.getElementById('hdnSelectedFields').Value = '" + tempstring + "'; alert(window.opener.document.getElementById('hdnSelectedFields').Value);window.close(); } window.opener.document.forms[0].submit(); setTimeout(CloseParent, 5);</script>";
When I close the window the hdnSelectedFields value is set but when I access the hdnSelectedFields on parent window pageload it shows old value of hdnSelectedFields.
if you see the alert in JavaScriptit shows updated hdnSelectedFields value when parent is loaded completed.
Any suggestion how can I access hdnSelectedFields updated value on parent pageload.
Dee
The property of the input box you want is value, not Value.
first of all: you should go for the #-selector, as ids must be unique per definition!
in your popup:
$(document).ready(function() {
setTimeout(function() {
var hiddenField = $('#hdnSelectedFields', window.opener);
// you could do some checking here, eg. hiddenField.length for ensuring existance
hiddenField.val('new value');
alert(hiddenField.val()); // for debug reason
window.opener.document.forms[0].submit();
window.close();
}, 5);
});
in your opener:
$(document).ready(function() {
var hiddenField = $('#hdnSelectedFields');
var hiddenFieldValue = hiddenField.val();
alert(hiddenFieldValue); // for debug reason
});
edit:
your fatal mistake is following:
function CloseParent() {
window.opener.document.getElementById('hdnSelectedFields').Value = '" + hdnCheckedAttribute.Value + "';
window.close();
}
window.opener.document.forms[0].submit();
setTimeout(CloseParent, 15);
so, what will happen when you open the popup?
... biiig drum roll!
submit the form
wait 15ms
set the hiddenField
somewhere in between pt 1 and 3 your $(document).ready() of your opener happens ...
missing pt 3 (due to parallelism), no value is set to the hiddenField.
you might see my workaround in my solution for your popup, which states:
setTimeout(function() {
[...]
window.opener.document.forms[0].submit();
window.close();
}, 5);
window.opener.$('#hiddenvariable').val('somevalue');

Open a pop up window maximumize to the user's screen configuration

What is best way to open a pop up window maximized to the user's screen configuration? I am using C# ASP.NET 3.5 web site project.
Update:
#Anthony - The windows xp task bar covers up some of the browser window. How do I set to maxmmumize and stop at the windows xp task bar?
Update 1:
I used the following the solution to maxumize the pop up window, but it opens the window first then moves it to the upper left corner of the screen. Is there a way just to open the pop up at the 0,0 position?
function openMaxWindow(url) {
var name = "MyWindow";
var features = "status=1,toolbar=1,location=1,menubar=1,scrollbars=1,resizable=1,top=0,left=0,height=" + screen.availHeight + ",width=" + screen.availWidth;
var newWindow = window.open(url, name, features);
}
Update 2:
Figured it out, I needed to add top=0 and left=0 to the features list.
Use javascript to run
var newWindow = window.open(); newWindow.resizeTo(screen.width, screen.height);
Obviously, you need to use the appropriate parameters to the window.open() statement.
This link also shows how to do it
Edit
newWindow.moveTo(0,0);
newWindow.resizeTo(screen.availWidth, screen.availHeight);
function maximizeWindow() {
window.moveTo(0, 0);
if (document.all) {
top.window.resizeTo(screen.availWidth,screen.availHeight);
} else if (document.layers||document.getElementById) {
if (top.window.innerHeight < screen.availHeight || top.window.innerWidth < screen.availWidth) {
top.window.outerHeight = screen.availHeight;
top.window.outerWidth = screen.availWidth;
}
}
}

Resources