473,806 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

firefox doesn't like the IE specific 'event' identifier and just quits running script

Hi
Firefox does not support the IE specific 'event' identifier and just quits
running the script.
..... even though the identifier only turns up in code marked for IE only ...

Does this seem reasonable?

The script is here:
http://www.lunds.us/private/coolclock.htm

This is the offending bit of script:
function Mouse(evnt){
ymouse =
(ns)?evnt.pageY +ClockFromMouse Y-(window.pageYOf fset):event.y+C lockFromMouseY;
xmouse = (ns)?evnt.pageX +ClockFromMouse X:event.x+Clock FromMouseX;
}Is there a neat workaround?chee rs, cw

Jul 23 '05 #1
5 3063
code_wrong wrote:
Hi
Firefox does not support the IE specific 'event' identifier and just quits
running the script.
.... even though the identifier only turns up in code marked for IE only ...
Your script may not doing what you think it is. If I'm running
Firefox, what value will the global variables "ie" and "ns" have
after this:

ns=(document.la yers);
ie=(document.al l);

If you guessed "undefined" , you're right. So when you go to
execute your "code marked for IE only" (excuse trimming):

ymouse = (ns)?evnt.pageY +... : event.y+ClockFr omMouseY;

What you are testing is not whether "ie" is true but whether
"ns" is true. Since ns is undefined, the test returns false and
your code tries to execute the stuff you've "marked for ie only".

Does this seem reasonable?

Depends on what your view of what is "reasonable ". Using
detection of a single feature to infer the UA and hence
support for an entire environment is fatally flawed (as you've
discovered). That is probably unreasonable.
The script is here:
http://www.lunds.us/private/coolclock.htm

This is the offending bit of script:
Offensive? :-)
function Mouse(evnt){
ymouse =
(ns)?evnt.pageY +ClockFromMouse Y-(window.pageYOf fset):event.y+C lockFromMouseY;
xmouse = (ns)?evnt.pageX +ClockFromMouse X:event.x+Clock FromMouseX;
}Is there a neat workaround?chee rs, cw


Yes. Ditch browser detection completely. Use feature
detection. Detect and use W3C stuff first, if it fails, try
other (usually IE) stuff.

To fix your event issue,

function Mouse(evnt){
var e = evnt || window.event;

if (e.clientY)
ymouse = e.clientY+Clock FromMouseY;

} else if (e.y) {
ymouse = e.y+ClockFromMo useY;

} else if (e.pageY) {
ymouse = e.pageY+ClockFr omMouseY-(window.pageYOf fset);
}
}

Untested, but IIRC clientX and clientY are the W3C properties
you are looking for that are equivalent to x and y. They are
supported by IE 6 (and maybe earlier), testing for them first
will suit perhaps 99% of browsers (i.e. only old IE and old
Netscape will want something else).
--
Fred
Jul 23 '05 #2
Fred Oz wrote:
[...]

Ooops, left out xmouse. Only need to feature detect once (it's
very likely that if clientY is supported, so is clientX...):

function Mouse(evnt){
var e = evnt || window.event;

if (e.clientY)
ymouse = e.clientY+Clock FromMouseY; xmouse = e.clientX++Cloc kFromMouseX;
} else if (e.y) {
ymouse = e.y+ClockFromMo useY; xmouse = e.x+ClockFromMo useX;
} else if (e.pageY) {
ymouse = e.pageY+ClockFr omMouseY-(window.pageYOf fset); xmouse = e.pageX+ClockFr omMouseX; }
}


--
Fred
Jul 23 '05 #3
Fred Oz wrote:
Fred Oz wrote:
[...]
Ooops, left out xmouse. Only need to feature detect once (it's
very likely that if clientY is supported, so is clientX...):
function Mouse(evnt){
var e = evnt || window.event;

if (e.clientY)
ymouse = e.clientY+Clock FromMouseY;

xmouse = e.clientX++Cloc kFromMouseX;

<snip>

It probably is valid to assume that an event object supporting clientX
will also support clientY. However, The style of testing you have
applied is problematic because the values being referred to are
primitive and so a type-converting test will produce results that depend
on the actual value. While an unsupported property will be undefined and
so type-convert to boolean false a numeric zero value (or an empty
string) will also type-convert to false. Where a property to be
tested/verified is an object or function, that will be undefined when
not implemented (and possibly null where supported but not present in
context), type-converting tests are probably optimum. Where a property
is expected to have a primitive value when implement a - typeof - test
is often necessary to produce reliable results.

Unfortunately, - typeof - testing is less efficient, but it can be
arranged that the testing does not need to be repeated each time a value
is read; the initial assumption still applies, if an event object
implements clientX the first time it is tested then the chances are good
that all (mouse related) event will also implement clientX, etc.

Richard.
Jul 23 '05 #4
code_wrong wrote:
Firefox does not support the IE specific 'event' identifier and just quits
running the script.
.... even though the identifier only turns up in code marked for IE only ...

Does this seem reasonable?

Frankly, yes it does. Consider this:-

You visit Russia. While there, you go to Lenin's Tomb and ask the guide
to explain how to see his personal effects. You ask in French. Do you
get upset because the guide only speaks Russian?

Javascript is a standard language and an interpreter using that standard
language recognises the standard terms of the language. If you throw in
terms that are not part of the languange, then it is no suprise when
they turn out to be meaningless.
Jul 23 '05 #5
Richard Cornford wrote:
Fred Oz wrote:
Fred Oz wrote: [...]
function Mouse(evnt){
var e = evnt || window.event;

if (e.clientY)
ymouse = e.clientY+Clock FromMouseY;
[...]
It probably is valid to assume that an event object supporting clientX
will also support clientY. However, The style of testing you have
applied is problematic because the values being referred to are
primitive and so a type-converting test will produce results that depend
on the actual value. While an unsupported property will be undefined and
so type-convert to boolean false a numeric zero value (or an empty
string) will also type-convert to false. Where a property to be
tested/verified is an object or function, that will be undefined when
not implemented (and possibly null where supported but not present in
context), type-converting tests are probably optimum. Where a property
is expected to have a primitive value when implement a - typeof - test
is often necessary to produce reliable results.

[...]

Thank you Richard ;-)

In case the OP missed it...

function Mouse(evnt){
var e = evnt || window.event;

if (typeof(e.clien tY)){
ymouse = e.clientY+Clock FromMouseY;
...
}

If clientY is supported, typeof(e.client Y) will return "number"
or something other than "undefined" I guess and hence be
evaluated to true (or not false). I don't have a browser that
doesn't support it so untested .

--
Fred
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
10569
by: coolsti | last post by:
Can someone help me enhance this code snippet which works only for IE so that it will also work for Firefox? I have been trying all sorts of things and have gotten to where I can capture the keydown and keypress events in Firefox, but then I can't seem to get the key code. I also don't know if the window.event.srcElement.type works with Firefox or if the onkeydown="return false" is valid in Firefox. I have this Javascript at the end of...
4
9308
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form action="MaintNotification.php?ReqID=5" method="post" name="frm5"> <tr align="left" bgcolor="#dddddd" class="text" onClick="submit()"
3
2959
by: niconedz | last post by:
Hi The following code works fine in IE but not Firefox. It's a little script that zooms an image and resizes the window to fit. Can anybody tell me what's wrong? Thanks Nico == btw.. sorry for the long post ==
5
3515
by: Martin Chen | last post by:
I have a frame set (as per MS FrontPage 2000). It has a contents and a main frame. The contents frame has a menu bar written with with javascript (in the context of a table). In IE6.1 everything works fine as it also does in firefox if I call the contents frame directly (i.e. outside of its frameset). However, if I call my main page (index.html) which invokes the frame set, the contents frame javascript menubar onmouseover function...
10
19178
by: Danny | last post by:
Hi all, I am having some odd problems with AJAX on Firefox (1.5). When I use GET as the request method everything works ok, but when I do a POST the remote function doesn't get the parameters I am passing to it. Everything works fine on IE 6. Here's a couple samples of what I am doing: // using GET url = 'http://www.myserver.com/cgi-bin/funct?key1=value1&key2=value2'
10
3057
by: Paul Gorodyansky | last post by:
Hi, Ran into the problem today - in INPUT field Firefox executes clean-yp of the content if a user presses Esc, _before_ control goes to the code via onkeydown - and search showed that it's a known issue: https://bugzilla.mozilla.org/show_bug.cgi?id=236628 The bug is closed due to the inactivity (I've just written to the Submiter because apparently I don't have rights to re-Open)
3
3081
by: Csaba Gabor | last post by:
Firefox's configuration settings (Prefs.js) can be accomplished via the interface at about:config. Q1. Is there any such setting that can be repeatedly altered via javascript (in a vanilla security environment), without having to request preivileges? By altered, I mean having it remain in effect the next time Firefox is restarted. Q2. If the answer to Q1 is affirmative, is there any such setting that could have an event associated...
7
9623
by: Coder | last post by:
Hi I have the following code in java script, it is not giving proper output in FIREFOX but running fine in IE... can anybody help me out to make this run in FIREFOX . <script language="JavaScript"> var cntlName; var eleTarget = document.getElementById('hiding'); function showOrHide(){
1
4229
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being aligned to the top, along with the slideshow and link buttons, you have to scroll down to see the text - how can I make IE6 display correctly? http://geekarama.co.uk/new_home.html here is the code for new_home.html and following that the CSS...
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9597
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10620
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10372
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10110
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.