473,378 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Does Event handlers work in netscape.

Does Event handlers work in netscape. If yes means can anyone please
help me.

<HTML><SCRIPT LANGUAGE="JScript">
function mouseclick() {
alert("I was clicked on " + window.event.srcElement.tagName);
}
</SCRIPT>
<BODY onclick="mouseclick()">
<H1>Welcome!</H1>
<P>This is a very <B>short</B> document.

</BODY>
</HTML>

The above script works fine in IE

But not in Netscape 7.2 :((

Jul 23 '05 #1
9 1725
testing

Jul 23 '05 #2
ch***************@gmail.com wrote:
The above script works fine in IE
But not in Netscape 7.2 :((


Try this modification:

function mouseclick(e) {
var what = e.target || e.srcElement;
if (what) alert("I was clicked on " + what.tagName);
}
[...]
<body onclick="mouseclick(event)">

ciao, dhgm
Jul 23 '05 #3
Dietmar Meier wrote:
ch***************@gmail.com wrote:
The above script works fine in IE
But not in Netscape 7.2 :((

Try this modification:

function mouseclick(e) {


if (!e && window.event) var e = window.event;

I'm not near an IE box right now, but I think to keep IE happy you'll
need to add the above line before:
var what = e.target || e.srcElement;

[...]

I'm playing in Safari at the moment, it seems to support a bit of both
Firefox/Netscape and IE (but often neither...) so I can't test it in
IE.

You may only need the extra line if you don't pass 'event' with the
onclick call.
--
Rob
Jul 23 '05 #4


ch***************@gmail.com wrote:
Does Event handlers work in netscape.
Yes, event handlers work in Netscape, depending on the Netscape version
not all event handlers specified in HTML 4 might work but with Netscape
6/7 there is certainly support for HTML 4 and for DOM Level 2 Events.
<HTML><SCRIPT LANGUAGE="JScript">
function mouseclick() {
alert("I was clicked on " + window.event.srcElement.tagName);
Have you checked the JavaScript console? It probably shows you that
window.event
is undefined or not an object with Netscape 6/7
<BODY onclick="mouseclick()">


so the problem is not that the onclick handler is not being fired but
that your script being called then throws an error.
You can pass the event object to a function e.g.
<body onclick="mouseclick(event);">
and then you need to process that argument in the function e.g.
function mouseclick (evt) {
and then you need to be aware that properties of the event object differ
in IE and in Netscape, IE docs are here:
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/obj_event.asp>
Netscape 6/7 implements the W3C DOM as given here:
<http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-Event>
<http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-UIEvent>
<http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-MouseEvent>

You already got an answer showing to access target with Netscape (or
other browser supporting that) and srcElement with IE (or other browsers
supporting that).
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #5


RobG wrote:
Dietmar Meier wrote:
Try this modification:

function mouseclick(e) {

if (!e && window.event) var e = window.event;

I'm not near an IE box right now, but I think to keep IE happy you'll
need to add the above line before:
var what = e.target || e.srcElement;

You may only need the extra line if you don't pass 'event' with the
onclick call.


And Dietmar had
<body onclick="mouseclick(event)">
in his answer so your line is not needed with his solution.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #6
Martin Honnen wrote:
ch***************@gmail.com wrote: <snip>
<HTML><SCRIPT LANGUAGE="JScript">

^^^^^^^
<snip> ... but
that your script being called then throws an error.

<snip>

The script certainly would error if executed in Netscape/Mozilla, but
would they execute script specified as language="JSCRIPT" in the first
palace?

Richard.
Jul 23 '05 #7
Thanks for your code. But its not working in Netscape, same problem

Jul 23 '05 #8
ch***************@gmail.com wrote:
Thanks for your code. But its not working in Netscape, same problem


In addition to my code, see Richard's answer. Instead of

<SCRIPT LANGUAGE="JScript">

(which is MSIE-proprietary) you should use

<script type="text/javascript">

to have your code executed in both Netscape7 and MSIE (and
other browsers). A complete example document would be:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Script-Type"
content="text/javascript">
<meta http-equiv="content-type"
content="text/html; charset=ISO-8859-1">
<title></title>
<script type="text/javascript">
function mouseclick(e) {
var what = e.target || e.srcElement;
if (what) alert("I was clicked on " + what.tagName);
}
</script>
</head>
<body onclick="mouseclick(event)">
<H1>Welcome!</H1>
<P>This is a very <B>short</B> document.
</body>
</html>

ciao, dhgm
Jul 23 '05 #9


Richard Cornford wrote:

ch***************@gmail.com wrote:


<HTML><SCRIPT LANGUAGE="JScript">


^^^^^^^

The script certainly would error if executed in Netscape/Mozilla, but
would they execute script specified as language="JSCRIPT" in the first
palace?


Good catch, Mozilla indeed ignores such a script block.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #10

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

Similar topics

3
by: Edwin Boersma | last post by:
Hi, I've just installed Netscape 7.1 for Linux and the following script refuses to open a window when I call this function: function OpenLinkWindow() { ...
6
by: Fredrik Celin | last post by:
If I add an event (to a div for example) with js, it replaces the event if there already is one. How can I add instead of replace this? Example: <body onLoad="testDiv.onmouseover =...
2
by: Ron D | last post by:
What is the equivalent of if (window.event.srcElement.id == "txt1ST_INIT_NM") in Netscape?
6
by: Amir Hardon | last post by:
I am dynamically adding rows to a table, and each row have a button which removes it. I have successfully implemented this for mozilla but I'm having troubles with IE, here is how I did it: ...
11
by: Saqib Ali | last post by:
Please excuse me, this is a fairly involved question that will likely require you to save the file below to a file and open it in a browser. I use Mozilla 1.5, so the problem I describe below...
3
by: Lachlan Hunt | last post by:
Hi, I've been looking up lots of documentation and trying to work out a cross-platform method of capturing a keyboard event and working out which key was pressed. From what I can find, there...
9
by: VK | last post by:
My original idea of two trains, however pictural it was, appeared to be wrong. The truth seems to be even more chaotic. IE implements its standard down-up model: any mouse event goes from the...
3
by: interuser | last post by:
Hi How can I prevent an event (eg button click) from happening from within page_load? The reason is that I want to make my existing application work for netscape, for which there are no client...
3
by: Islam Elkhayat | last post by:
I have master datagrid & master details in 5 panels each belong to diffrent dbtable. I have a dropdpwn list to switch which panel to be visible.. I also have one navigation bar for add, update,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.