I'm working on an HTA in which I would like to have a VBScript run if a user
clicks anywhere on the window - unless a control (e.g. a button or list box)
is clicked.

Is this possible? If so, could an example be posted please?

Thanks much!

Re: Get window click unless on a control by ThatsIT

ThatsIT
Thu May 10 08:37:17 CDT 2007


"XP" <XP@discussions.microsoft.com> wrote in message
news:9A64AFFA-7826-4BB1-9ACC-F0D20609302F@microsoft.com...
> I'm working on an HTA in which I would like to have a VBScript run if a
> user
> clicks anywhere on the window - unless a control (e.g. a button or list
> box)
> is clicked.
>
> Is this possible? If so, could an example be posted please?
>


for each button you would need to add some code to its onclick event handler

like this


window.event.cancelBubble = true
return false

> Thanks much!


Re: Get window click unless on a control by XP

XP
Thu May 10 08:47:01 CDT 2007

Hi,

In order to get the whole window, where do you recommend I put the
"OnClick=" and can you give me an example of the command needed?

Thanks...

"ThatsIT.net.au" wrote:

>
> "XP" <XP@discussions.microsoft.com> wrote in message
> news:9A64AFFA-7826-4BB1-9ACC-F0D20609302F@microsoft.com...
> > I'm working on an HTA in which I would like to have a VBScript run if a
> > user
> > clicks anywhere on the window - unless a control (e.g. a button or list
> > box)
> > is clicked.
> >
> > Is this possible? If so, could an example be posted please?
> >
>
>
> for each button you would need to add some code to its onclick event handler
>
> like this
>
>
> window.event.cancelBubble = true
> return false
>
> > Thanks much!
>

Re: Get window click unless on a control by mayayana

mayayana
Thu May 10 09:10:27 CDT 2007

You can probably do it with this in a
document_onclick sub:

If window.event.srcElement.tagName = "BODY" Then...

Two caveats:

1) You might want to deal with case, to be on
the safe side, by doing something like:
UCase(window.event.srcElement.tagName)

2) In many cases you won't actually be over BODY. You
might be over a DIV, TD, SPAN, etc. So you
might want to do a Select Case something like the
following:

Select Case UCase(window.event.srcElement.tagName)

Case "SELECT", "INPUT"
Exit sub
End Select

> I'm working on an HTA in which I would like to have a VBScript run if a
user
> clicks anywhere on the window - unless a control (e.g. a button or list
box)
> is clicked.
>
> Is this possible? If so, could an example be posted please?
>
> Thanks much!



Re: Get window click unless on a control by XP

XP
Thu May 10 09:41:01 CDT 2007

Hello again Mayayana,

Please forgive my ignorance, I hope you may be able to help me out in a
little more detail; but suppose I have a list box:

<Div ID="lbxSourceFiles">
<Select Name=lbxSource...>

Now, I don't want the window click to detect a click on this control, so how
would my Sub look?

Sub Document_OnClick

If Window.Event.???.??? = "BODY" Then
?????
End IF

End Sub

Thanks so much for your help...

"mayayana" wrote:

> You can probably do it with this in a
> document_onclick sub:
>
> If window.event.srcElement.tagName = "BODY" Then...
>
> Two caveats:
>
> 1) You might want to deal with case, to be on
> the safe side, by doing something like:
> UCase(window.event.srcElement.tagName)
>
> 2) In many cases you won't actually be over BODY. You
> might be over a DIV, TD, SPAN, etc. So you
> might want to do a Select Case something like the
> following:
>
> Select Case UCase(window.event.srcElement.tagName)
>
> Case "SELECT", "INPUT"
> Exit sub
> End Select
>
> > I'm working on an HTA in which I would like to have a VBScript run if a
> user
> > clicks anywhere on the window - unless a control (e.g. a button or list
> box)
> > is clicked.
> >
> > Is this possible? If so, could an example be posted please?
> >
> > Thanks much!
>
>
>

Re: Get window click unless on a control by Ayush

Ayush
Thu May 10 09:56:10 CDT 2007

[XP]s message :
> Hello again Mayayana,
>
> Please forgive my ignorance, I hope you may be able to help me out in a
> little more detail; but suppose I have a list box:
>
> <Div ID="lbxSourceFiles">
> <Select Name=lbxSource...>
>
> Now, I don't want the window click to detect a click on this control, so how
> would my Sub look?
>
> Sub Document_OnClick
>
> If Window.Event.???.??? = "BODY" Then
> ?????
> End IF
>


DisabledOn="A|INPUT|BUTTON|SELECT"

Sub Document_OnClick
Set regxp=New RegExp:regxp.ignoreCase=true
regxp.pattern=DisabledOn
If regxp.test(window.event.srcElement.tagname) Then Exit Sub


CODE TO RUN

End Sub


Good Luck, Ayush.
--
VBScript, JScript, WSH Reference : http://www.devguru.com/

Re: Get window click unless on a control by mayayana

mayayana
Thu May 10 10:32:23 CDT 2007


> <Div ID="lbxSourceFiles">
> <Select Name=lbxSource...>
>
> Now, I don't want the window click to detect a click on this control, so
how
> would my Sub look?
>

You can do the cancel, as posted above, by ThatsIT.net.au.
That would go something like:
--------
Sub lbxSource_onclick()
window.event.cancelBubble = true
End Sub
--------

That would prevent the click from "bubbling up".
In other words, it stops the event from being "fired"
at document level.

But you said that you wanted to run your script only
if the window is clicked and ignore the click if it was
on any button, listbox, or other control. If you use the
cancelBubble method then you need to name, and write
a sub for, all SELECT and INPUTobjects. By using
the window.event in the document_onclick sub you can
get the same result with just one sub.

Window.event has a property srcElement, which is basically
the "tag object" that was clicked. So if you use
window.event.srcElement then you now have a reference
to the tag associated with the click and you can access
any property of that tag. Since all tags have a name
property in the IE DOM, you can use that if you want to.

window.event.srcElement.tagName returns the HTML
tag that was clicked: DIV, SPAN, TD, INPUT, BODY, etc.

window.event.srcElement.name will return the tag name,
if any.

So if you do the following and click on your listbox...
-------
Sub Document_OnClick
msgbox window.event.srcElement.tagName & "-" &
window.event.srcElement.name
End Sub
-------
...then you should see a msgbox that says "SELECT-lbxSource".


So what I was describing originally was a way to avoid
needing to deal with cancelling each individual object
event, since what you really want is a body_onclick sub.
Since a listbox is a SELECT tag, and a button
is an INPUT tag, you can respond to any click in the
window - but not when it's on the listbox or a button -
by using:

Sub Document_OnClick()
Dim sTagType
sTagType = UCase(window.event.srcElement.tagName)

Select Case sTagType
Case "SELECT", "INPUT" '-- listbox, textbox, button, etc. clicked.
Exit Sub
Case else '-- this could be BODY, TD, SPAN, etc.
msgbox "This is reacting to a click in the window."
End Select
End Sub

You could also filter all buttons but not text fields by
using:

Select Case sTagType
Case "SELECT"
Exit Sub
Case "INPUT"
'-- drop out clicks on buttons but not on input fields:
if window.event.srcElement.type = "button" then Exit Sub
Case else
msgbox "This is reacting to a click in the window."
End Select




Re: Get window click unless on a control by XP

XP
Thu May 10 11:56:01 CDT 2007

Hi Mayayana,

Crystal clear now. Thanks so much for taking all the time to respond so
thoroughly! Thanks so much!

"mayayana" wrote:

>
> > <Div ID="lbxSourceFiles">
> > <Select Name=lbxSource...>
> >
> > Now, I don't want the window click to detect a click on this control, so
> how
> > would my Sub look?
> >
>
> You can do the cancel, as posted above, by ThatsIT.net.au.
> That would go something like:
> --------
> Sub lbxSource_onclick()
> window.event.cancelBubble = true
> End Sub
> --------
>
> That would prevent the click from "bubbling up".
> In other words, it stops the event from being "fired"
> at document level.
>
> But you said that you wanted to run your script only
> if the window is clicked and ignore the click if it was
> on any button, listbox, or other control. If you use the
> cancelBubble method then you need to name, and write
> a sub for, all SELECT and INPUTobjects. By using
> the window.event in the document_onclick sub you can
> get the same result with just one sub.
>
> Window.event has a property srcElement, which is basically
> the "tag object" that was clicked. So if you use
> window.event.srcElement then you now have a reference
> to the tag associated with the click and you can access
> any property of that tag. Since all tags have a name
> property in the IE DOM, you can use that if you want to.
>
> window.event.srcElement.tagName returns the HTML
> tag that was clicked: DIV, SPAN, TD, INPUT, BODY, etc.
>
> window.event.srcElement.name will return the tag name,
> if any.
>
> So if you do the following and click on your listbox...
> -------
> Sub Document_OnClick
> msgbox window.event.srcElement.tagName & "-" &
> window.event.srcElement.name
> End Sub
> -------
> ....then you should see a msgbox that says "SELECT-lbxSource".
>
>
> So what I was describing originally was a way to avoid
> needing to deal with cancelling each individual object
> event, since what you really want is a body_onclick sub.
> Since a listbox is a SELECT tag, and a button
> is an INPUT tag, you can respond to any click in the
> window - but not when it's on the listbox or a button -
> by using:
>
> Sub Document_OnClick()
> Dim sTagType
> sTagType = UCase(window.event.srcElement.tagName)
>
> Select Case sTagType
> Case "SELECT", "INPUT" '-- listbox, textbox, button, etc. clicked.
> Exit Sub
> Case else '-- this could be BODY, TD, SPAN, etc.
> msgbox "This is reacting to a click in the window."
> End Select
> End Sub
>
> You could also filter all buttons but not text fields by
> using:
>
> Select Case sTagType
> Case "SELECT"
> Exit Sub
> Case "INPUT"
> '-- drop out clicks on buttons but not on input fields:
> if window.event.srcElement.type = "button" then Exit Sub
> Case else
> msgbox "This is reacting to a click in the window."
> End Select
>
>
>
>

Re: Get window click unless on a control by ThatsIT

ThatsIT
Fri May 11 09:00:23 CDT 2007


"XP" <XP@discussions.microsoft.com> wrote in message
news:D9B0C491-4409-4822-8577-A95BB8B643E6@microsoft.com...
> Hi,
>
> In order to get the whole window, where do you recommend I put the
> "OnClick=" and can you give me an example of the command needed?
>


lets say you have a button in a table,

when you click on the button the button onclick event is fired, then the
tables onclick event is fired and finally the documents onclick event is
fired., this is called the event bubble.

if you were to put
"window.event.cancelBubble = true"
into the onclick event the table on click and the window onclick events
would not fire.
if you were to put it into the tables onclick event handler then the button
and the tables events would fire but not the documents.



> Thanks...
>
> "ThatsIT.net.au" wrote:
>
>>
>> "XP" <XP@discussions.microsoft.com> wrote in message
>> news:9A64AFFA-7826-4BB1-9ACC-F0D20609302F@microsoft.com...
>> > I'm working on an HTA in which I would like to have a VBScript run if a
>> > user
>> > clicks anywhere on the window - unless a control (e.g. a button or list
>> > box)
>> > is clicked.
>> >
>> > Is this possible? If so, could an example be posted please?
>> >
>>
>>
>> for each button you would need to add some code to its onclick event
>> handler
>>
>> like this
>>
>>
>> window.event.cancelBubble = true
>> return false
>>
>> > Thanks much!
>>