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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mouse click anywhere

Status
Not open for further replies.

WebRic

Technical User
Joined
Sep 21, 2004
Messages
95
Location
GB
Hi All,

Is there a way of detecting a mouse click anywhere in the screen?

I'm want a layer to appear which allows the user to click in and if they click off the layer it closes.

What's the best way to go about this?


Richard
 
I think I coul dlive with that.... What would I need to do to detect that?
 
You can use the onclick event. Something like this:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
<html lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
	<meta http-equiv="content-language" content="en">
	<title>Mouse click test</title>

	<script type="text/javascript">
	<!--

		function popMessage(e) {
			if (!e) e = event;
			var xPos = yPos = 0;
			xPos = (e.pageX) ? e.pageX : e.clientX + document.body.scrollLeft;
			yPos = (e.pageY) ? e.pageY : e.clientY + document.body.scrollTop;
			nDiv = document.createElement('div');
			nDiv.appendChild(document.createTextNode('Div at ' + xPos + ',' + yPos));
			nDiv.style.position = 'absolute';
			nDiv.style.left = xPos + 'px';
			nDiv.style.top = yPos + 'px';
			document.getElementsByTagName('body')[0].appendChild(nDiv);
		}

		document.onclick = popMessage;
	//-->
	</script>
</head>

<body>
	Click anywhere here!
</body>
</html>

I wrote that for a thread a long time ago, but can't find it using the search function.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
the search function leaves much to be desired...



*cLFlaVA
----------------------------
spinning-dollar-sign.gif
headbang.gif
spinning-dollar-sign.gif

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Indeed it does. I'd love to know if the search function searches code snippets or not. It would be downright daft if it does not, given the nature of this site.

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I finally tracked down the thread (using the manual search method) here:

thread216-1004751

Apologies to elegidito - I had thought the original code was mine, but clearly it was not.

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks for the help.

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top