Reply
Mouse event and firefox
Old 10-19-2004, 10:55 AM Mouse event and firefox
Sarpidon's Avatar
Novice Talker

Posts: 5
Can please someone tell me why the following script only works with IE and not Firefox. The problem is with event.clientY and evenct.clientX no matter what I do I cannot get firefox to capture mouse coordinates from withing the script. Only if I put the event.clientY directly to the link I can do so (eg. onclick="javascript:window.open"'xxx.htm','example ',width=200,height=150,top='+event.clientY+', left='+event.clientX+' ... but this is something I do now want to do. Please help!!!

function openwin(url,x,y,nam)

{


var nwin = window.open(url,nam,"resizable=0, menubar=0, status=0, toolbar=0, directories=0, location=0, scrollbars=1, fullscreen=0")
nwin.resizeTo(x, y);

var posy = event.clientY;
var posx = event.clientX;

nwin.moveTo(posx,posy);
}
Sarpidon is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 10-19-2004, 11:09 AM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Use browser sniffing!

Code:
 
var isOpera, isIE, isNav, isFox, isOther = false;
if (navigator.userAgent.indexOf("Opera")!=-1) {
 isOpera = true;
} else if (navigator.userAgent.indexOf("Firefox")!=-1) {
 isFox = true;
} else if (navigator.appName == "Microsoft Internet Explorer") {
 isIE = true;
} else if (navigator.appName == "Netscape") {
 isNav = true;
} else {
 isOther = true;
}
 
	if (isIE)
	{
	 OffsetX = window.event.offsetX;
	 OffsetY = window.event.offsetY;
	} else {
	 OffsetX = e.pageX - document.getElementById("divImage").offsetLeft;
	 OffsetY = e.pageY - document.getElementById("divImage").offsetTop;
	}
I'm not sure what you want the coordinates to be relative to (The document or the object that fired the event). The code above is attached to the onMouseDown event of a DIV. It returns coordinates relative to the top-left of the document. (Unless you put the DIV inside another DIV with the CSS Position set to Relative, in which case it returns coordinates relative to the top left of that DIV). You might have to play with it a bit to get it to work the way you want...
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Inoxia Pyrotechnics Supplies | Surrey Angels Cheerleading Squad
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 10-19-2004, 11:53 AM
Sarpidon's Avatar
Novice Talker

Posts: 5
I get it now. Thank you
Sarpidon is offline
Reply With Quote
View Public Profile
 
Old 10-19-2004, 12:54 PM
Sarpidon's Avatar
Novice Talker

Posts: 5
Aparently I cannot make it work in firefox. I'll make it simple. Let's say I want to click on a page and at the point were I click I want an image on a new window to appear, ok how do I do that? The only way I can make it work in firefox is this : <span class="popup" onMouseOver="style.cursor='pointer';" onclick="javascript:window.open('../../../images/sporoi/scagliola.jpg','example','width=170,height=220,top ='+event.clientY+',left='+event.clientX+',director ies=no,location=no,menubar=no,scrollbars=no,status =no,toolbar=no,resizable=no');">clickme</span>

but I do not want to use this.... any ideas?
Sarpidon is offline
Reply With Quote
View Public Profile
 
Old 10-19-2004, 02:18 PM
Extreme Talker

Posts: 158
You need to supply the event, this is predefined but needs to be explicit, so I've made it a function parameter.

Try this:

<html>
<head>
<title>Event</title>
<script>
function openwin(url,x,y,nam,event)
{
var nwin = window.open(url,nam,"resizable=0, menubar=0, status=0, toolbar=0, directories=0, location=0, scrollbars=1")
nwin.resizeTo(x, y);

var posy = event.clientY;
var posx = event.clientX;

nwin.moveTo(posx,posy);
}
</script>
</head>
<body onClick="openwin('somepage.htm',100,100,'childWin' ,event)">
</body>
</html>
ElectricSheep is offline
Reply With Quote
View Public Profile
 
Old 10-19-2004, 02:36 PM
Sarpidon's Avatar
Novice Talker

Posts: 5
You are right it works. thank you !!! that is exactly what I wanted.
Sarpidon is offline
Reply With Quote
View Public Profile
 
Old 01-27-2005, 09:00 AM
stratplan's Avatar
Novice Talker

Posts: 6
Neat solution, Electric! Impressive.
__________________
--
Stratplan
stratplan is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Mouse event and firefox
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13866 seconds with 13 queries