473,698 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ns4,6,ie5,6 and mozilla

I have this script and I want to adapt it to the DOM of most / all well
known browsers like mozilla and netscape.. at the moment it only works in
ie4+ en ns6. can anybody give me some hints ?!?
This is used for making a tree <li><ul>

var ns6 = document.getEle mentById && !document.all;
var ie4 = document.all && navigator.userA gent.indexOf("O pera") == -1;

function checkcontained( e)
{
var iscontained = 0;
cur = ns6 ? e.target : event.srcElemen t;
if (cur.id == "foldheader ")
{
iscontained = 1;
}
else
{
while (ns6 && cur.parentNode || (ie4 && cur.parentEleme nt))
{
if (cur.id == "foldheader " || cur.id == "foldinglis t")
{
iscontained = (cur.id == "foldheader ") ? 1 : 0;
break;
}
cur = ns6 ? cur.parentNode : cur.parentEleme nt;
}
}
if (iscontained)
{
var foldercontent = ns6 ? cur.nextSibling .nextSibling :
cur.all.tags("U L")[0];
if (foldercontent. style.display == "none")
{
foldercontent.s tyle.display = "";
cur.style.listS tyleImage = "url(images/open.gif)";
}
else
{
foldercontent.s tyle.display = "none";
cur.style.listS tyleImage = "url(images/fold.gif)";
}
}
}

if (ie4 || ns6)
{
document.onclic k = checkcontained;
}
Jul 20 '05 #1
6 3300
"Daniel" <dv*****@planet .nl> writes:
I have this script and I want to adapt it to the DOM of most / all well
known browsers like mozilla and netscape.. at the moment it only works in
ie4+ en ns6. can anybody give me some hints ?!?
Which browsers have you tried it in?
What error messages did they give?

Which browsers are you not supporting? E.g., not dinosaurs like
Netscape 4, where supporting it basically means writing two versions
of everything. It seems you are ignoring NS 4 (smart!).
This is used for making a tree <li><ul> var ns6 = document.getEle mentById && !document.all;
var ie4 = document.all && navigator.userA gent.indexOf("O pera") == -1;
The first hint is to *not* try to identify all existing browsers.

Browser detection is best saved for the situations where standards
break down, and where you know that a specific browser has a usable
workaround.
function checkcontained( e)
{
var iscontained = 0;
cur = ns6 ? e.target : event.srcElemen t;
My event handlers usually start out like this:

function checkcontained( event)
{
event = event || window.event; // IE sucks
var cur = event.target || event.srcElemen t; // IE sucks

(Yes, I always include the comments :)
There is no mention of "ns6" in this. It uses event.target if it is there,
no matter which, potentially unrecognized, browser is being used.
while (ns6 && cur.parentNode || (ie4 && cur.parentEleme nt))
while ( cur.parentNode || cur.parentEleme nt )

Again, don't detect the browser and assume the browser is the one
you think. Just test for the property you actually need. If it is
there, use it. If not, do something else. No need to know the name
of the browser for that.
if (cur.id == "foldheader " || cur.id == "foldinglis t")
{
iscontained = (cur.id == "foldheader ") ? 1 : 0;
Don't use "1" and "0" for boolean values. The language has "true" and
"false", and unless you are going to do arithmetic, you are just wasting
bits and processing power converting them to booleans later.

iscontained = (cur.id == "foldheader ");
cur = ns6 ? cur.parentNode : cur.parentEleme nt;
cur = cur.parentNode || cur.parentEleme nt;

var foldercontent = ns6 ? cur.nextSibling .nextSibling :
cur.all.tags("U L")[0];
var foldercontent;
if (cur.nextSiblin g) {
foldercontent = cur.nextSibling .nextSibling;
} else if (cur.getElement sByTagName) {
foldercontent = cur.getElements ByTagName("ul")[0];
} else if (cur.all && cur.all.tags) {
foldercontent = cur.all.tags("U L")[0];
}

Object detection, not browser detection.
if (foldercontent. style.display == "none")
You should be aware that browsers as late as Opera 6 and Konqueror 3
don't allow you to change the display style dynamically. If you
support these, you might want to use visibility:hidd en instead.
document.onclic k = checkcontained;


If you really want to follow the DOM specification, use:

if (document.addEv entListener) {
document.addEve ntListener("cli ck",checkcontai ned,false);
} else if (document.attac hEvent) {
document.attach Event("onclick" ,checkcontained );
} else {
document.onclic k = checkcontained;
}

Most of your exceptions are for IE, and most of these even for IE 4
(which is used less than Netscape 4). There are still points where
even IE 6 needs a helping hand, though.

Hope this helps.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

"Lasse Reichstein Nielsen" <lr*@hotpop.com > schreef in bericht
news:u1******** **@hotpop.com.. .
"Daniel" <dv*****@planet .nl> writes:
I have this script and I want to adapt it to the DOM of most / all well
known browsers like mozilla and netscape.. at the moment it only works in
ie4+ en ns6. can anybody give me some hints ?!?
Which browsers have you tried it in?


Currenly I am trying this in Mozilla 1.4 and IE6
What error messages did they give?
IE6 doesn't give any errors..
NS6 gives the error that the foldercontent has no properties
Which browsers are you not supporting? E.g., not dinosaurs like
Netscape 4, where supporting it basically means writing two versions
of everything. It seems you are ignoring NS 4 (smart!).


I wanna support at least NS6, Mozilla and IE6 and maybe 5 the most common
used once...
var foldercontent = ns6 ? cur.nextSibling .nextSibling :

cur.all.tags("U L")[0];

var foldercontent;
if (cur.nextSiblin g) {
foldercontent = cur.nextSibling .nextSibling;
} else if (cur.getElement sByTagName) {
foldercontent = cur.getElements ByTagName("ul")[0];
} else if (cur.all && cur.all.tags) {
foldercontent = cur.all.tags("U L")[0];
}


Unfortunately this didn't work
The menu structure was very disturbed :(
>> stripped the rest.. :)


new code

//*******
// Still needing the next 2 lines :(
//*******
var ns6 = document.getEle mentById && !document.all;
var ie4 = document.all && navigator.userA gent.indexOf("O pera") == -1;

function checkcontained( variable)
{
if (typeof variable == 'undefined') variable = window.event;
var cur = (typeof variable.target != 'undefined') ? variable.target :
variable.srcEle ment;
var iscontained = 0;
if (cur.id == "foldheader ")
{
iscontained = 1;
}
else
{
while ( cur.parentNode || cur.parentEleme nt )
{
if (cur.id == "foldheader " || cur.id == "foldinglis t")
{
iscontained = (cur.id == "foldheader ");
break;
}
cur = cur.parentNode || cur.parentEleme nt;
}
}
if (iscontained)
{

//*******
// Here it goes wrong
//*******
var foldercontent = ns6 ? cur.nextSibling .nextSibling :
cur.all.tags("U L")[0];
if (foldercontent. style.display == "none")
{
foldercontent.s tyle.display = "";
cur.style.listS tyleImage = "url(images/open.gif)";
}
else
{
foldercontent.s tyle.display = "none";
cur.style.listS tyleImage = "url(images/fold.gif)";
}
}
}

if (document.addEv entListener)
{
document.addEve ntListener("cli ck",checkcontai ned,false);
}
else if (document.attac hEvent)
{
document.attach Event("onclick" ,checkcontained );
}
else
{
document.onclic k = checkcontained;
}
Jul 20 '05 #3
"Daniel van den Oord" <da*******@plan et-maps-on.nl> writes:
NS6 gives the error that the foldercontent has no properties
Ok, that probably means that foldercontent is null or undefined.
I wanna support at least NS6, Mozilla and IE6 and maybe 5 the most common
used once...
Aiming for standards should give you Mozilla and Netscape 7 (and
Netscape 6 if you avoid the bugs ... it is based on a pre-1.0
version of Mozilla and has some bugs)
var foldercontent = ns6 ? cur.nextSibling .nextSibling :

cur.all.tags("U L")[0];

var foldercontent;
if (cur.nextSiblin g) {
foldercontent = cur.nextSibling .nextSibling;
} else if (cur.getElement sByTagName) {
foldercontent = cur.getElements ByTagName("ul")[0];
} else if (cur.all && cur.all.tags) {
foldercontent = cur.all.tags("U L")[0];
}


Unfortunately this didn't work
The menu structure was very disturbed :(


Thinking about it, it is not that supricing. The oringinal expression
didn't make much sense either:

var foldercontent = ns6 ? cur.nextSibling .nextSibling :
cur.all.tags("U L")[0];

If it is NS6, you let foldercontent be a sibling of the cur node. That
is, they are nodes on the same level, having the same parent node.
If it is not NS6, you find a child node of the cur node.

So, which is it? Without knowing the structure of the HTML it is hard
to guess which it should be, but since it works in IE, the problem is
probably the nextSibling part. I would just skip it and use:

var foldercontent;
if (cur.getElement sByTagName) {
foldercontent = cur.getElements ByTagName("ul")[0];
} else if (cur.all && cur.all.tags) {
foldercontent = cur.all.tags("U L")[0];
}

That should at least do the same thing in both Mozilla and IE.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4

"Lasse Reichstein Nielsen" <lr*@hotpop.com > schreef in bericht
news:fz******** **@hotpop.com.. .
"Daniel van den Oord" <da*******@plan et-maps-on.nl> writes:
NS6 gives the error that the foldercontent has no properties
Ok, that probably means that foldercontent is null or undefined.
I wanna support at least NS6, Mozilla and IE6 and maybe 5 the most common used once...


Aiming for standards should give you Mozilla and Netscape 7 (and
Netscape 6 if you avoid the bugs ... it is based on a pre-1.0
version of Mozilla and has some bugs)


I know I'm trying to keep things save... I allready made a lot of
workarounds in other scripts
most of them to ugly to show though ;)
> var foldercontent = ns6 ? cur.nextSibling .nextSibling :
cur.all.tags("U L")[0];

var foldercontent;
if (cur.nextSiblin g) {
foldercontent = cur.nextSibling .nextSibling;
} else if (cur.getElement sByTagName) {
foldercontent = cur.getElements ByTagName("ul")[0];
} else if (cur.all && cur.all.tags) {
foldercontent = cur.all.tags("U L")[0];
}
Unfortunately this didn't work
The menu structure was very disturbed :(


Thinking about it, it is not that supricing. The oringinal expression
didn't make much sense either:

var foldercontent = ns6 ? cur.nextSibling .nextSibling :
cur.all.tags("U L")[0];


You got that right it never worked here ;)

If it is NS6, you let foldercontent be a sibling of the cur node. That
is, they are nodes on the same level, having the same parent node.
If it is not NS6, you find a child node of the cur node.

So, which is it? Without knowing the structure of the HTML it is hard
to guess which it should be, but since it works in IE, the problem is
probably the nextSibling part. I would just skip it and use:

var foldercontent;
if (cur.getElement sByTagName) {
foldercontent = cur.getElements ByTagName("ul")[0];
} else if (cur.all && cur.all.tags) {
foldercontent = cur.all.tags("U L")[0];
}

That should at least do the same thing in both Mozilla and IE.


Well I wished still nothing in foldercontent.. .

I'm sorry I totally forgot about the html code ;) here it is.. partially ;)

<div style="position :relative;left:-24">
<ul>
<li id="foldheader" > Modulen</li>
<ul id="foldinglist " style="display: none" style=&{head};>

<li id="foldheader" > Gebruikers</li>
<ul id="foldinglist " style="display: none" style=&{head};> </ul>

<li id="foldheader" > Modulen</li>
<ul id="foldinglist " style="display: none" style=&{head};>
<li><a
href="javascrip t:menulinks('ed 801965714921239 3e5bf995c2c9431 ')">
Install</a></li>
</ul>

<li id="foldheader" > Servers</li>
<ul id="foldinglist " style="display: none" style=&{head};>
<li><a
href="javascrip t:menulinks('e4 f2e95c8f850458f 86a264bf792d0e8 ')">
IP-adressen</a></li>
<li><a
href="javascrip t:menulinks('11 066639b238708c8 41da006e1166dda ')">
Locaties</a></li>
<li><a
href="javascrip t:menulinks('3e 8c653b2ee35059f c0a94d568953238 ')">
Servers</a></li>
<li><a
href="javascrip t:menulinks('1c e826ae5f9dbd78c 19cab92da1f3330 ')">
Software</a></li>
<li><a
href="javascrip t:menulinks('e7 d0cc30504eaa9be 0f21e394370c217 ')"> Type
Software</a></li>
</ul>
<li><a
href="javascrip t:menulinks('e1 c31bf61d9937925 173075207517770 ')"> Quick
Links</a></li>
</ul>
</ul>
</div>
Jul 20 '05 #5
"Daniel van den Oord" <da*******@plan et-maps-on.nl> writes:
Well I wished still nothing in foldercontent.. . I'm sorry I totally forgot about the html code ;) here it is.. partially ;)

<div style="position :relative;left:-24">
<ul>
<li id="foldheader" > Modulen</li>
<ul id="foldinglist " style="display: none" style=&{head};>


Ok, have you ever validated this code? (Hint: it won't)

You are not allowed to have ul elements as direct children of other ul
elements. They must be inside an li element.
That is, a menu item is something like

<li>Modulen
<ul>
...
</ul>
<li>

The submenu of Modulen is inside the same li element as the title.

If written like that, the getElementsByTa gName/all.tags code should
find the submenu correctly.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #6

"Lasse Reichstein Nielsen" <lr*@hotpop.com > schreef in bericht
news:7k******** **@hotpop.com.. .
"Daniel van den Oord" <da*******@plan et-maps-on.nl> writes:
Well I wished still nothing in foldercontent.. .

I'm sorry I totally forgot about the html code ;) here it is.. partially ;)
<div style="position :relative;left:-24">
<ul>
<li id="foldheader" > Modulen</li>
<ul id="foldinglist " style="display: none" style=&{head};>


Ok, have you ever validated this code? (Hint: it won't)

You are not allowed to have ul elements as direct children of other ul
elements. They must be inside an li element.
That is, a menu item is something like

<li>Modulen
<ul>
...
</ul>
<li>

The submenu of Modulen is inside the same li element as the title.

If written like that, the getElementsByTa gName/all.tags code should
find the submenu correctly.


HEhe I allready was very confused with the code.... Now I know why....
Thanks a lot men... thanks a bunch
Jul 20 '05 #7

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

Similar topics

0
1773
by: melledge | last post by:
Mozilla Foundation Co-Hosts Europe's Leading XML and Web Developer Conference XTech 2005 Conference to Bring Together XML and Web Technology Thought Leaders
15
7288
by: Peter Bremer | last post by:
Hi all, I've written this little piece of code, which doesn't seem to work in Mozilla 1.5. I haven't tried it on other Gecko browsers, but I've found some indication that Netscape 6+ has the same problem. Internet Explorer 6 and Opera 7 have no problems with it. <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'> <script>document.write (window.history.length);</script>
3
1659
by: Jim Ley | last post by:
Hi, It seems the mozilla guys have chosen another (almost certainly poor choice in my initial thoughts) of having document.all evaluate to false, but document.all catch the chicken event - also document.all.tags will work. It seems that the document.all not evaluating to true is to stop the really dumb object assumption scripts to fail and the document.all scripts that don't bother with any object detection to all of a sudden
10
2369
by: News | last post by:
I have a page up trying to learn how to ID a browser and other info. http://wyght.com/warren/testPos.html here is the code <script type = "text/javascript"> var space = ", "; var name = navigator.appName;
0
8609
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
9166
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...
0
9030
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
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
7737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5861
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
4371
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...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.