detect mouse click event

  • Thread starter samuelberthelot
  • Start date
S

samuelberthelot

Hi,
When I click on a link it shows a div above all other elements of my
page (a kind of popup). I would like to close it(hide the div again)
when the user clicks anywhere on the screen. How can i do that? The
'event listener' should only be activated if the div is visible.

thanks
 
E

Evertjan.

wrote on 07 jul 2006 in comp.lang.javascript:
When I click on a link it shows a div above all other elements of my
page (a kind of popup). I would like to close it(hide the div again)
when the user clicks anywhere on the screen. How can i do that? The
'event listener' should only be activated if the div is visible.

<body onclick='if(thatDivDisplayBlock)thatDivDisplayNone()'>
 
S

samuelberthelot

Thanks.
I can't access the body from my page as it is in a master page (i'm
doing asp.net). However I have a javascript function bodyLoad() which
is called at body load and in which I can do stuff. How can I assigne
the onclick event in this function ?
 
E

Evertjan.

wrote on 07 jul 2006 in comp.lang.javascript:
[please skip the signature in replies,
or have a decent newsreader do that automagically]

[please do not toppost on usenet, corrected]
I can't access the body from my page as it is in a master page (i'm
doing asp.net). However I have a javascript function bodyLoad() which
is called at body load and in which I can do stuff. How can I assigne
the onclick event in this function ?

I would have no idea about "bodyLoad()": if this is asp.net, better ask
an asp.net group.

What is a master-page? Are you using iframes? Or is the <body> set in a
include?

what about:

body.onload = myfunc; // Use no () !

function myfunc() {
if (thatDiv.display != 'none') // this line could be skipped ;-)
thatDiv.display = 'none';
};

not tested
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top