473,788 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="expand Div('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.userA gent;
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(NameO fCookie)
{

if (document.cooki e.length > 0)
{

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

begin += NameOfCookie.le ngth+1;
end = document.cookie .indexOf(";", begin);
if (end == -1) end = document.cookie .length;
return unescape(docume nt.cookie.subst ring(begin, end)); }
}
return "menu1";

}

function setCookie(NameO fCookie, value, expiredays)
{

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

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

function closeall()
{
var objs;

if (ie)
{
objs = document.all.ta gs("DIV");
}
else if (ua)
{
objs = document.getEle mentById("DIV") ;
}
else if (document.layer s)
{
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.getEl ementById(what) .style.display == "none") {
document.getEle mentById(what). style.display = "";
} else {
document.getEle mentById(what). style.display = "none";
}
}

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

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

Jul 23 '05 #1
3 2448
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.userA gent;
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.getEl ementById) {
objs = document.getEle mentById('DIV') ;
} else if (document.all) {
objs = document.all['DIV'];
} else if (document.layer s) {
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.lengt h; i<len; i++) {
...

[...] if (document.getEl ementById(what) .style.display == "none") {
document.getEle mentById(what). style.display = "";
} else {
document.getEle mentById(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.getEl ementById) {
objs = document.getEle mentById('DIV') ;
} else if (document.all) {
objs = document.all['DIV'];
} else if (document.layer s) {
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("thin gsmenu", tahw, 7);
closeall();

what = tahw + "_menu"

if (document.getEl ementById(what) .style.display ==
"none") {
document.getEle mentById(what). style.display = "")
} else if (document.all) {
document.all['DIV'](what).style.di splay = "none");
} else if (document.layer s) {
document.all['DIV'](what).style.di splay = "none");
}
else {
document.getEle mentById(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.getEl ementById) {
objs = document.getEle mentById('DIV') ;


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

if (document.getEl ementsByTagName ) {
objs = document.getEle mentsByTagName( '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
6846
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 these problems is using document.layers. I have Google'd for examples of how to use the document object specifically with Mozilla, but I cannot find anything that explains why my problems occur. Could anyone here see through the included example...
12
10176
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 scrollbar, you get the height of the entire document, screwing up any chance of centering a window in the browser using these values. Is there a way to get the height of the actual browser window and not the entire page height? Thanks.
10
54906
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 idea! function closeall() { var objs;
4
3229
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 that I could externalize my JavaScript, but that will not be practical throughout this application. Is there any way to get around this issue? Xalan processor. Stripped down stylesheet below along with XHTML output. <?xml version='1.0'?>...
29
2820
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 Netscape 4 if you save your page in .aspx
4
5624
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 FireFox and Safari it appears as a narrow column of text with only 2-3 words per line. Here is the code: function showAll()
7
8035
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 seem to find the correct invocation to get the field to appear in Firefox. I've copied below the call and the html of the field itself. Can anyone point me to what is wrong with it and more to the point, how to
3
4647
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 javascript that keeps the layer persistent for the HEIGHT, but not WIDTH in IE7. Of course it works great in the other browsers... Can anyone see what is wrong with the script? Any help would be so good - I have tried everything my limited knowledge...
1
4223
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
9498
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
10173
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...
0
9967
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
7517
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
5399
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
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
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
2
3674
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.