Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-16-2005, 06:30 PM   PM User | #1
MusicMan
New to the CF scene

 
Join Date: Feb 2005
Location: So Cal
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
MusicMan is an unknown quantity at this point
Question Help with browser compatibility issue - clickHandler() in DOM2

Greetings,

I recently discovered that some JS code used in some important support pages which work fine with IE do not work in browsers such as Netscape 7.2 and Firefox (any Mozilla browser?). A JS console message indicates "window.event" has no properties. Apparently there is no window.event in the DOM2 event model use by those browsers. I inherited this code and am not well-versed in JS, so I'm not real clear on what I need to do. Is there a JS pro out there that can help me out?

The page emulates an explorer-like function, with a line of text and a plus box to the left that can be clicked to reveal the details of the item. The plus box becomes a minus box which can be clicked to hide the details - basically a toggle function.

The HTML tags look like this:

<img src="./images/plus.gif" ID="M1" Class="Outline" Style="cursor:hand" width=11 height=11>&nbsp;<b>Specifications</b>
...[table stuff]...
<div ID="M1d" Style="display:none"><ul>......</ul>

...and the javascript in the page is as follows:


function clickHandler() {
var targetId, srcElement, targetElement;
srcElement = window.event.srcElement;
if (srcElement.className == "Outline") {
targetId = srcElement.id + "d";
targetElement = document.all(targetId);
if (targetElement.style.display == "none") {
targetElement.style.display = "";
srcElement.src = "images/minus.gif";
} else {
targetElement.style.display = "none";
srcElement.src = "images/plus.gif";
}
}
}
document.onclick = clickHandler;


Firefiox, NS7.2, etc. just do nothing at all when the plus icon is clicked, only IE works. Any help would be appreciated. Thanks.
MusicMan is offline   Reply With Quote
Old 02-17-2005, 12:40 AM   PM User | #2
MusicMan
New to the CF scene

 
Join Date: Feb 2005
Location: So Cal
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
MusicMan is an unknown quantity at this point
Nevermind - I've dealt with it. I just threw out that JS code completely and created a solution using CSS instead.
MusicMan is offline   Reply With Quote
Old 03-30-2005, 05:20 PM   PM User | #3
scrupul0us
Regular Coder

 
Join Date: Sep 2004
Posts: 230
Thanks: 1
Thanked 0 Times in 0 Posts
scrupul0us can only hope to improve
what was your CSS solution?
scrupul0us is offline   Reply With Quote
Old 04-01-2005, 09:39 AM   PM User | #4
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
window.event is an event model specific to IE. For crossbrowser solutions see also

here

By short, the crossbrowser solution could be something like

PHP Code:
var myElem;
function 
captureEvent(e){
if (!
e) {myElem=event.srcElement}//if IE and compatible
else{myElem=e.target}//if Moz and compatible (DOM rec)
.....
.....

__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

Last edited by Kor; 04-01-2005 at 09:47 AM..
Kor is offline   Reply With Quote
Old 04-01-2005, 09:10 PM   PM User | #5
MusicMan
New to the CF scene

 
Join Date: Feb 2005
Location: So Cal
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
MusicMan is an unknown quantity at this point
clickHandler() solution

I guess its part CSS, part JS. I used the CSS display property along with an id selector inside a div tag. Then two little JS functions just set document.getElementByID("id").style.display to either "none" or "block". Works great!
MusicMan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:46 AM.


Advertisement
Log in to turn off these ads.