473,793 Members | 2,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A problem with an apparently common JS menu...

I am attempting to make a web page more Netscape friendly... <a
href="http:www. gordonceilings. com"></a>

I have already corrected the table issues in an offline staging site
(where I do the building and then move it to the live site when ready),
so don't worry about those. My problem lies in the menu on the left. It
shows up and the initial links work in Netscape 8, but the menu will
not drop down to show the sub-selections. I can get the sub-menus to
drop down with "document.getEl ementById" arguments, but the rest of the
menu won't move down accordingly to make room, making for a jumbled
mess. It works flawlessly in IE5 and 6 with either document.all or
getElementById, but in looking for an answer I see that IE is more
forgiving...

Here is the script, it seems to be a common one:

<SCRIPT LANGUAGE="JavaS cript">

// ADDITIONAL NOTES
// The input variables to the toggle function are the number of the
submenu to open/close,
// starting with 0, and the number of pixels to move the objects below.
// For example toggle(1,60) opens/closes the second submenu and moves
the objects below 60 pixels.

var nom = 10; // Number of menus
var usePictures = 0; // use pictures? 1 = yes, 0 = no

var ttls = new Array(); // An array for the title objects
var subs = new Array(); // An array for the submenu objects
var lastn;
var lastmove;

if (document.layer s) {
visible = 'show';
hidden = 'hide';
}
else
if (document.all) {
visible = 'visible';
hidden = 'hidden';
}
for (var i = 1; i <= nom; i++) {
ttls[i] = ('title' + i);
subs[i] = ('submenu' +i);
}
function picopen(n) {
title = ('title' + n);
pic = ('pic' + n);
if (document.layer s) {
document.layers[title].document.image s[pic].src = "opened.gif ";
}
else if (document.all) {
document.all(pi c).src = "opened.gif ";
}
}
function picclose(n) {
title = ('title' + n);
pic = ('pic' + n);
if (document.layer s) {
document.layers[title].document.image s[pic].src = "closed.gif ";
}
else if (document.all) {
document.all(pi c).src = "closed.gif ";
}
}
lastn = (nom + 1);
lastmove = 0;
function lasttoggle(n,mo ve) {
if (n <= nom) {
menu = ('submenu' + n);
if (document.layer s) {
submenu = document.layers[menu];
}
else if (document.all) {
submenu = document.all(me nu).style;
}
if (submenu.visibi lity == visible) {
submenu.visibil ity = hidden;
for (var i = (n+1); i <= nom; i++) {
if (document.layer s) {
document.layers[ttls[i]].top -= move;
document.layers[subs[i]].top -= move;
}
else if (document.all) {
document.all(tt ls[i]).style.pixelTo p -= move;
document.all(su bs[i]).style.pixelTo p -= move;
}
}
}
}
}
function toggle(n,move) {
menu = ('submenu' + n);
if (document.layer s) {
submenu = document.layers[menu];
}
else if (document.all) {
submenu = document.all(me nu).style;
}
if (submenu.visibi lity == visible) {
submenu.visibil ity = hidden;
if (usePictures) picclose(n);
for (var i = (n+1); i <= nom; i++) {
if (document.layer s) {
document.layers[ttls[i]].top -= move;
document.layers[subs[i]].top -= move;
}
else if (document.all) {
document.all(tt ls[i]).style.pixelTo p -= move;
document.all(su bs[i]).style.pixelTo p -= move;
}
}
}
else {
submenu.visibil ity = visible;
if (usePictures) picopen(n);
if (lastn != n) {
lasttoggle(last n,lastmove);
}
for (var i = (n+1); i <= nom; i++) {
if (document.layer s) {
document.layers[ttls[i]].top += move;
document.layers[subs[i]].top += move;
}
if (document.all) {
document.all(tt ls[i]).style.pixelTo p += move;
document.all(su bs[i]).style.pixelTo p += move;
}
}
}
lastn = n;
lastmove = move;
}
function loadFrames(fram e1,page1) {
eval("parent."+ frame1+".locati on='"+page1+"'" );
}
// End -->

</script>

So far all I can find concerning this script is people that are having
problems with it... maybe it's time for a new script, but I really
don't want to have to rebuild the menu...

Nov 23 '05
14 1939
VK wrote:
<snip>
Netscape 4.x is gone, but as a reminder document.layers are still
supported (or at least do not return undefined > false) on some
browsers, for example Netscape (what a surprise!) or Safari.
This statement is false. Anyone surprised by that?

<snip> 1. Remove all "if (document.layer s) {...}" branches completely
2. Replace all "else if (document.all)" with "if
(document.getEl ementById)"
3. Go through the text and replace all "document.a ll("
strings with "document.getEl ementById("
4. Save and test.


Advice best considered with an eye to the veracity of the statement
above.

Richard.
Nov 23 '05 #11
Lasse Reichstein Nielsen wrote:
Thomas 'PointedEars' Lahn <Po*********@we b.de> writes:
and therefore error-prone (MS may recognize this bug and remove
it in future IE versions with you having to deal with the
consequences):
Unlikely.


I have seen it snow in June.
At times I wish they would forget about backwards compatability
and do things right instead, but it's not the way they work.


Upcoming IE7 may present a change in that policy. Hopefully.
the same property cannot be both non-function and function.


Then it's a function (i.e., an object with a [[Call]] method).
Functions are objects, so it's not impossible to have properties
that work with the property access operator at the same time.


But if it is indeed a function, should it then not have all properties
of Function objects and what is if a member is named like a property of
Function objects? This all still seems very strange to me.
PointedEars
Nov 23 '05 #12
Bryan wrote:
Invalid markup, insufficient feature tests, proprietary referencing,
evil[tm] eval(), and nonsensical, potential harmful comments (in that
order) ... what do you expect?

If I knew, I wouldn't need to ask... :P

I removed all comments, got rid of eval, now I just need to know what
part of the markup is invalid, what is "proprietar y referencing", and
what feature tests I should run...

It still runs perfectly in IE, but the menu doesn't budge in Netscape
when the submenu is made visible...


http://www.alistapart.com/articles/horizdropdowns/


Code now looks like:

<SCRIPT LANGUAGE="JavaS cript">


The language attribute is deprecated, type is required:

<script type="text/javascript">
Ta Tom :-)

[...]

The rest of your script is amazingly complex for something so simple.
Loading the href into the main frame is achieved with a target
attribute, so the 'loadframe' function seems redundant and makes your
page unnecessarily reliant on scripting.

Try the following - it works whether scripting is enabled or not (links
have been truncated to '#' and target attributes removed for the sake of
the simplicity). It needs further work before commercial use but shows
an alternative approach that doesn't require any in-page scripting: it
is dependent on the page structure and the use of matching 'titlex' and
'submenux' ids numbered consecutively from 1.

I've moved the submenu divs inside the title divs and allowed the
document flow to place elements. Use CSS to adjust their position, not
absolute positioning.

Feature testing is done up-front - if scripting or suitable features
aren't supported, the menus are shown in full (i.e. your site remains
fully functional).
<html>
<head>
<title>Loopy stuff</title>
<style type="text/css">
..submenu{
padding-left: 20px;
}
</style>

<script type="text/javascript">

var smRefs = [];

function toggleSubs(){
var div = this.parentNode ;
while (div.parentNode && 'div' != div.nodeName.to LowerCase()){
div = div.parentNode;
}
var num = div.id.replace(/title/,'');
for (var i=0, len=smRefs.leng th; i<len; ++i){
if (i != num && smRefs[i]) smRefs[i].style.display = 'none';
}
smRefs[num].style.display =
('none' == smRefs[num].style.display) ? '':'none';
}

function registerMenus() {

var body = document.body || document.docume ntElement;

// Do appropriate feature tests
if (!document.getE lementById || !body || !body.style) return;

var i=0, el;
while ((el = document.getEle mentById('title ' + ++i))){
smRefs[i] = document.getEle mentById('subme nu' + i)
smRefs[i].style.display = 'none';
var firstA = el.firstChild;
while ('a' != firstA.nodeName .toLowerCase()) {
firstA = firstA.nextSibl ing;
}
firstA.onclick = toggleSubs;
}
}

</script>
</head>
<body onload="registe rMenus();">

<div class="title" id="title1">
<a href="#">Column Covers</a>
<div class="submenu" id="submenu1">
<a href="#">Produc t Data</a><br>
<a href="#">Galler y</a>
</div>
</div>

<div class="title" id="title2">
<a href="#">Ceilin g Specialties</a>
<div class="submenu" id="submenu2">
<a href="#">Perime ter Pockets</a><br>
<a href="#">Column Collars</a><br>
<a href="#">Partit ion Closures</a><br>
<a href="#">Baffle Ceilings</a><br>
</div>
</div>

</body>
</html>


--
Rob
Nov 23 '05 #13
Thomas 'PointedEars' Lahn said the following on 11/15/2005 5:38 PM:
Bryan wrote:

<SCRIPT LANGUAGE="JavaS cript">
[...]
else if (document.all) {
document.all( ttls[i]).style.pixelTo p -= move;
document.all( subs[i]).style.pixelTo p -= move;
[...]
function loadFrames(fram e1,page1) {
eval("parent. "+frame1+".loca tion='"+page1+" '");
}
// End -->
[...]
</script>

So far all I can find concerning this script is people that are having
problems with it... maybe it's time for a new script, but I really
don't want to have to rebuild the menu...

Invalid markup, insufficient feature tests, proprietary referencing,
evil[tm] eval(), and nonsensical, potential harmful comments (in that
order) ... what do you expect?


Perhaps someone to lead him in the right direction other than the FAQ?
Maybe, as David did, give some useful advice?

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 23 '05 #14
Thomas 'PointedEars' Lahn <Po*********@we b.de> writes:

[document.all]
But if it is indeed a function, should it then not have all properties
of Function objects and what is if a member is named like a property of
Function objects? This all still seems very strange to me.


It's a host object, so it doesn't have to follow the conventions of
language objects. An object is a function if it has the internal
[[Call]] method, it doesn't have to inherit from Function.protot ype
(ECMA262 section 8.6.2). And indeed it doesn't ("document.all. apply"
is undefined, and "document.a ll instanceof Function" is false).
The value of "typeof document.all" is "object", but typeof on host
objects is also allowed to be implementation dependent.

But document.all doesn't violate any rules of ECMAScript for a host
object.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Nov 23 '05 #15

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

Similar topics

3
2468
by: bill drescher | last post by:
The menu at: http://www.alsacreations.com/articles/deroulant/cssmenu.htm does exactly what I want, except: If you leave a menu (and submenu) by going _down_ to the next menu the first does not close. If you exit the menu to the right side it does. Is this a Mozilla bug (1.5) , or a desired effect of the css ? IF neither, how can I make the menu close when I leave the submenu on the bottom ? --
10
3487
by: Haines Brown | last post by:
I've implemented the horizontal drop down menu discussed recently in this newsgroup, and it works nicely under Galeon and Mozilla, but not IE 5.0. Here are the problems: Under IE 5.0, the there is no drop down menu functionality at all. I wanted to implement an alternative stylesheet for IE, but my link to it is apparently broken. What is wrong with my link? I'd
10
3113
by: H.S. | last post by:
Hi, Let me begin by saying that I am not an HTML expert. The most experience I have for HTML authoring is when I made my webpages in my grad studies at my university and some on my home computer for experiments. I am however familiar with programming languages and am quite familiar with Linux (use Debian Testing). I am in the process of revamping my old old old webpage. I have decided not to use frames for now and try to made do...
8
1546
by: RCS | last post by:
All, OK, so I'm working on a template for our new ASP.NET applications. Part of this, includes using the new menu and breadcrumbs control in ASP.NET 2.0 (I'm using beta 2). I put the hierarchy of the applications and navigation in a database, and am able to pull that into the app by inheriting StaticSiteMapProvider. So that's set and works great.
17
1838
by: John Bailo | last post by:
What does he do all day? Find out here: http://channel9.msdn.com/Showpost.aspx?postid=163166
0
1500
by: john_mcmahon | last post by:
I'm having issues populating a second drop down menu that's dependent upon a selection in the first menu. When I select an option from the first menu, the second menu remains disabled, i.e. unable to select an option. I'm confident that most of my code is correct because of testing that I completed with it. For instance, when I remove the ParentControlID attribute from the second control and un-comment out: // string sPlantTypeID = "2";...
1
1720
by: rfr | last post by:
Apparently the Transitional Doctype kills this script because the script does not make proper use of units like "px". It works well without a doctype statement. But once someone adds a transitional doctype, the js script no longer works. Can someone familiar with javascript bring it up-to-date so that it works with current doctypes and post it here for others to make use of? The whole HTML document including the js scrip follows (...
0
2197
by: raylopez99 | last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to modify a Point, which I had made have a property. It's pointless to do this (initially it will compile, but you'll run into problems later). Apparently Point is a struct, a value type, and it does not behave like a classic structure (in my mind's eye, and see below). Traditionally I think of a classic structure as simply an object where every member is public. But with...
5
13383
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
9670
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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
10430
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
10211
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
9033
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...
1
7538
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
5436
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
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4111
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

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.