469,579 Members | 1,098 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Events in Mozilla and firefox?

The following works fine in IE -> what am I missing to make it work in
Firefox - an example would be great?

I can't figure it out :-)
------------------------------------------------
<body>

<script language="javascript">
var IE = document.all?true:false;
if (!IE) document.captureEvents(event.MOUSEMOVE);
document.onmousemove = getMouseXY;

var x,y,tmpcords;

function getMouseXY(e) {
if(IE){
x = event.clientX + document.body.scrollLeft;
y = event.clientY + document.body.scrollTop;
} else {
x = e.pageX;
y = e.pageY;
}

//Check if length is above 1200
if(document.all._clientEyeTextbox.value.length > 1200){
return calc();
document.all._clientEyeTextbox.value = '';
} else {
document.all._clientEyeTextbox.value =
document.all._clientEyeTextbox.value + x + ',' + y + ',';
//document.all.a.value = document.all.a.value + x + ',' + y + ',';
}
}
</script>

</body>
------------------------------------------------

Best regards

Michael Christensen

Oct 24 '05 #1
3 5560
Michael Christensen said the following on 10/24/2005 2:08 PM:
The following works fine in IE -> what am I missing to make it work in
Firefox - an example would be great?

I can't figure it out :-)


Try Tools>Javascript Console
Stop assuming that the existence of document.all means you are dealing
with IE - it doesn't.
Stop thinking you need to know what browser you are dealing with - you
don't.
Start feature detecting.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 24 '05 #2
Michael Christensen wrote:
The following works fine in IE -> what am I missing to make it work in
Firefox - an example would be great?

I can't figure it out :-)
------------------------------------------------
<body>

<script language="javascript">
The language attribute is depreciated, type is required:

<script type="text/javascript">

var IE = document.all?true:false;
When posting code, indent using 2 or 4 spaces, not tabs. It helps to
stop wrapping which nearly always introduces errors. Manually wrap code
at about 70 characters (same reason).

As Randy said, browser detection based on whether or not certain
functions are supported is flawed. Simply don't do it.

if (!IE) document.captureEvents(event.MOUSEMOVE);
For some reading about how/when to use captureEvents:

<URL:http://www.quirksmode.org/js/events_order.html>
<URL:http://www.quirksmode.org/js/events_netscape4.html>

Remove the -- if (!IE)... -- line...

document.onmousemove = getMouseXY;
And add this one here...

if (document.captureEvents){
document.captureEvents(Event.MOUSEMOVE);
}

var x,y,tmpcords;
It's probable that these globals aren't needed. If the issue is
returning multiple values from a function, you can do that by putting
them into an array and return that.


function getMouseXY(e) {
if(IE){
x = event.clientX + document.body.scrollLeft;
y = event.clientY + document.body.scrollTop;
} else {
x = e.pageX;
y = e.pageY;
}
Once you remove browser sniffing, the above becomes:

function getMouseXY(e)
{
var e = e || window.event;
if (e.pageX || e.pageY){
x = e.pageX;
y = e.pageY;
} else if (e.clientX || e.clientY) {
x = event.clientX + document.body.scrollLeft;
y = event.clientY + document.body.scrollTop;
}

<URL:http://www.quirksmode.org/js/events_properties.html>


//Check if length is above 1200
if(document.all._clientEyeTextbox.value.length > 1200){
What is _clientEyeTextbox? If it's the name of a form control, then the
best way to access it is to get a reference then use that ('formName' is
the name of the form):

var textBox = document.forms.formName._clientEyeTextbox;
if (1200 < textBox.value){
If _clientEyeTextBox is the id of the control, then it's invalid since
id attributes must start with a letter (it's OK for a name to start with
an underscore, but certain valid name characters will cause problems in
places depending on how you access the control). Read the HTML spec on
name and id attributes.

return calc();
The function will end here if the if statement returned true.
document.all._clientEyeTextbox.value = '';
This line will not be reached, but if it is was it should be:

textBox.value = '';
} else {
document.all._clientEyeTextbox.value =
document.all._clientEyeTextbox.value + x + ',' + y + ',';
textBox.value += x + ',' + y + ',';

Since you seem to be storing x and y in the text box, they need not be
global variables. And if the text box is a device for passing the
values to some other function, you could use:

return [x, y];

to return the values in an array - but my assumption may be a wrong.

//document.all.a.value = document.all.a.value + x + ',' + y + ',';
}
}
</script>

</body>


All the above is untested - if you provide some working code with
associated HTML (minimal working example) then better help can be provided.

--
Rob
Oct 24 '05 #3
VK
> Events in Mozilla and firefox?

A bit offtopic but important to mention:
The question sounds similar to: "Difference between mammals and cows".
Any modern graphical browser is Mozilla meaning it has "Mozilla" in its
USER_AGENT string.

Oct 25 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

20 posts views Thread by David | last post: by
3 posts views Thread by Praveen | last post: by
9 posts views Thread by Lachlan Hunt | last post: by
2 posts views Thread by Arnaud Diederen | last post: by
5 posts views Thread by Richard Maher | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.