473,405 Members | 2,279 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,405 software developers and data experts.

IE, NS & Firerox Problem - DIVs, document.layers and getElementById

Thanks in Advance for any help on this - its truely sending my
head in loops... so I appreciate your efforts!

okay, I have a javascript listed below that drops down submenus
contained within:
<div class="small" style="display: none" id="menu1_menu">

when the heading is clicked:
<a href=.. onClick="expandDiv('menu1')">

- This works perfect in IE, NS6 (I Think), but not NS7 or
FireFox. I know my issues lay in the 'var Browsers = ' and
document.layers, getElementById. The menu is opened and set
using the function setMenu() called elsewhere... menu1 is the
default, but it does store a cookie if this changes to menu2,
menu3 etc...

Essentially i'd like this to work for all browsers - in fact its
essential it does :( - Please stop me from loosing anymore hair
- Regards Lee
var ua = navigator.userAgent;
var opera = /opera [56789]|opera\/[56789]/i.test(ua);
var ie = !opera && /msie [56789]/i.test(ua);
// preventing opera to be identified as ie
var moz = !opera && /mozilla\/[56789]/i.test(ua);
// preventing opera to be identified as mz

function getCookie(NameOfCookie)
{

if (document.cookie.length > 0)
{

begin = document.cookie.indexOf(NameOfCookie+"=");
if (begin != -1)
{

begin += NameOfCookie.length+1;
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); }
}
return "menu1";

}

function setCookie(NameOfCookie, value, expiredays)
{

var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 *
3600 * 1000));

document.cookie = NameOfCookie + "=" + escape(value) +
((expiredays == null) ? "" : "; expires=" +
ExpireDate.toGMTString());
}

function closeall()
{
var objs;

if (ie)
{
objs = document.all.tags("DIV");
}
else if (ua)
{
objs = document.getElementById("DIV");
}
else if (document.layers)
{
objs = document.layers["DIV"];
}
else
{
alert('Non supported browser');
}

for (var i=0; i<objs.length; i++) {
if (objs[i].className == "small")
{

objs[i].style.display = "none";
}
}
}

function expandDiv(tahw) {
setCookie("menu", tahw, 7);
closeall();

what = tahw + "_menu"

if (document.getElementById(what).style.display == "none") {
document.getElementById(what).style.display = "";
} else {
document.getElementById(what).style.display = "none";
}
}

function setmenu()
{
var menuvar;
menuvar = getCookie("menu");
expandDiv(menuvar);
}

----------------------------------------------
Posted with NewsLeecher v2.0 Beta 5
* Binary Usenet Leeching Made Easy
* http://www.newsleecher.com/?usenet
----------------------------------------------

Jul 23 '05 #1
3 2409
InvisibleMan wrote:
[...]
- This works perfect in IE, NS6 (I Think), but not NS7 or
FireFox. I know my issues lay in the 'var Browsers = ' and
document.layers, getElementById. The menu is opened and set
Then that's what I'll concentrate on fixing.
using the function setMenu() called elsewhere... menu1 is the
default, but it does store a cookie if this changes to menu2,
menu3 etc...

Essentially i'd like this to work for all browsers - in fact its
essential it does :( - Please stop me from loosing anymore hair
- Regards Lee
var ua = navigator.userAgent;
var opera = /opera [56789]|opera\/[56789]/i.test(ua);
var ie = !opera && /msie [56789]/i.test(ua);
// preventing opera to be identified as ie
var moz = !opera && /mozilla\/[56789]/i.test(ua);
// preventing opera to be identified as mz [...]

Get rid of the crappy browser detection. Try:

if (document.getElementById) {
objs = document.getElementById('DIV');
} else if (document.all) {
objs = document.all['DIV'];
} else if (document.layers) {
objs = document.all['DIV'];
}

...

[...]
for (var i=0; i<objs.length; i++) {
It is more efficient to get the length just once:

for (var i=0, var len=<objs.length; i<len; i++) {
...

[...] if (document.getElementById(what).style.display == "none") {
document.getElementById(what).style.display = "";
} else {
document.getElementById(what).style.display = "none";
}
}

And you'd better add feature detection (as above) here too, else the
non-getElementById browsers will fail.

That may not fix all your issues, but it should get you going again.

--
Fred
Jul 23 '05 #2
Thanks for that okay, i've done the following but keep getting
errors... i'm getting what your trying to say... but its not
working and causing errors... Help

function closeall(){
var objs;

if (document.getElementById) {
objs = document.getElementById('DIV');
} else if (document.all) {
objs = document.all['DIV'];
} else if (document.layers) {
objs = document.all['DIV'];
} else {
alert('Non supported browser');
}
for (var i=0; i<objs.length; i++) {
if (objs[i].className == "small")
{
objs[i].style.display = "none";
}
}
}

AND

function expandDiv(tahw) {
setCookie("thingsmenu", tahw, 7);
closeall();

what = tahw + "_menu"

if (document.getElementById(what).style.display ==
"none") {
document.getElementById(what).style.display = "")
} else if (document.all) {
document.all['DIV'](what).style.display = "none");
} else if (document.layers) {
document.all['DIV'](what).style.display = "none");
}
else {
document.getElementById(what).style.display = "none";
}
}

----------------------------------------------
Posted with NewsLeecher v2.0 Beta 5
* Binary Usenet Leeching Made Easy
* http://www.newsleecher.com/?usenet
----------------------------------------------

Jul 23 '05 #3
InvisibleMan wrote:
[...]
if (document.getElementById) {
objs = document.getElementById('DIV');


Sorry, I think what you are looking for is
document.getElementsByTagName:

if (document.getElementsByTagName) {
objs = document.getElementsByTagName('DIV');

and that will return a collection.

--
Fred
Jul 23 '05 #4

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

Similar topics

6
by: David List | last post by:
I'm having a problem using different properties of the document object in the example javascripts in my textbook with browsers that identify themselves as using the Mozilla engine. One example of...
12
by: Kepler | last post by:
How do you get the height of the client browser in IE? Both document.body.clientHeight and document.body.offsetHeight return the height of the document. If the page is long and there's a vertical...
10
by: InvisibleMan | last post by:
Hi, Thanks for any help in advance... Okay, I have the JS listed below that calls for the display of the (DIV) tag... cookie function not included, as don't feel its necessary but you'll get the...
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
29
by: amos | last post by:
Hi I'm experiencing a real nasty thing about dotnet. I've made a big application in dotnet and I would like to use ILAYERS for netscape 4. You CAN NOT USE Layers and Form buttons in...
4
by: drew197 | last post by:
I am a newbie. I am editing someone elses code to make it compatible with Firefox and Safari. In IE, when you click on the proper link, a block of text is shown in a nice paragraph form. But, in...
7
by: Paul Lautman | last post by:
Hi y'all, I found the toggle function (shown below) and applied it to a form of mine. It works fine in IE, but in Firefox it appears to fail on the eval lines. I've searched around but I can't...
3
by: Head In A Pan | last post by:
Hello - Yes - I know floating/persistent layers can be yucky - but for this project it is only tiny and contains some xy mouse coordinates for a map... buy anyway - here's my problem: I have a...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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,...
0
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...
0
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,...
0
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...

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.