Forum Moderators: open
<!-- tab Product start -->
<div id="tabProdIntro" class="tab1A" onMouseOver="style.cursor='hand';" onclick="showTabs('tabProdIntroActive', 'divIntro'), scrollbarPosition('divIntro');">Introductie</div>
<div id="tabProdIntroActive" class="tab1B" onMouseOver="style.cursor='hand';" onclick="showTabs('tabProdIntroActive', 'divIntro');" style="visibility:visible;">Introductie</div>
<!-- tab Product end -->
if you click tabProdIntro it runs showTabs which hides tabProdIntro and shows tabProdIntroActive (this tab has a different color and simulates the effects of a tabbed page). The style of tabProdIntroActive is set to active since this is the first tab and should be active. In the style of the tabs (classes tab1A & tab1B) I included two different images: the active tab-image and the inactive tab-image. It all works perfect in IE.
However...in Firefox the onclick event on this DIV does not seem to work. Is there a way to get it working?
You might try breaking out Venkman, the Moz JavaScript debugger. I'm not sure it's included in the FF download, but I'm sure it's available. It's included by default in Moz, itself. NS, too.
[b]function showTabs[/b](showtab, showdiv){
if (document.getElementById!= null)
document.getElementById(tabProdIntroActive).style.visibility='hidden';
document.getElementById(tabProdTestenActive).style.visibility='hidden';
document.getElementById(tabProdOntwerpActive).style.visibility='hidden';
document.getElementById(tabProdMaatPrijsActive).style.visibility='hidden';
document.getElementById(tabProdTestimonialsActive).style.visibility='hidden';
document.getElementById(divIntro).style.visibility='hidden';
document.getElementById(divOntwerp).style.visibility='hidden';
document.getElementById(divTesten).style.visibility='hidden';
document.getElementById(divMaatPrijs).style.visibility='hidden';
document.getElementById(divTestimonials).style.visibility='hidden';
document.getElementById[showtab].style.visibility='visible';
document.getElementById[showdiv].style.visibility='visible';
else if (document.all)
document.all.tabProdIntroActive.style.visibility='hidden';
document.all.tabProdTestenActive.style.visibility='hidden';
document.all.tabProdOntwerpActive.style.visibility='hidden';
document.all.tabProdMaatPrijsActive.style.visibility='hidden';
document.all.tabProdTestimonialsActive.style.visibility='hidden';
document.all.divIntro.style.visibility='hidden';
document.all.divOntwerp.style.visibility='hidden';
document.all.divTesten.style.visibility='hidden';
document.all.divMaatPrijs.style.visibility='hidden';
document.all.divTestimonials.style.visibility='hidden';
document.all[showtab].style.visibility='visible';
document.all[showdiv].style.visibility='visible';
}
Do the classes specified as your DIV paramteres include position attributes?
i.e.
.tab1A { position:relative }
.tab1B { position:absolute }
It used to be that Mozilla-based products needed a position attribute in order to recognize the DIV or LAYER element for script manipulation. In addition, Mozilla-based products did not used to recognize the "id" attribute, prefering the "name" attribute instead, although I imagine they should recognize it in the newer products.
Try adding a name="tab1A" to your DIV tags and including a "position:relative" attribute in your stylesheet.
[blue]var CSS_POINTER = "pointer"
if(document.all)
{
CSS_POINTER = "hand"
if(!document.getElementById)
document.getElementById = function(id){return this.all[id]}
}[/blue]
This means you can write:
onmouseover="this.style.cursor=CSS_POINTER" You can also do away with the
if(document.all) block in the showTabs function. A couple of lines have
getElementById used with square brackets. Best change them to round ones. function showTabs(showtab, showdiv){
If I change it in normal brackets then it will search for an ID called showtab & showdiv. But that is wrong. Or am I just thinking too much in the IE way :D
About the mousepointer: thanks gonna try that stylesheet with the pointer out. Looks good!
<div id="tabProdIntro" class="tab1A" onMouseOver="style.cursor='hand';" onclick="showTabs(getElementById('tabProdIntroActive'), ... )
Works on both and results in the same coding for the function.
Oh and I have seen one or two web sites go through and define the variables at the end of pages to overcome this i.e.
VAR tabProdIntroActive = getElementById('tabProdIntroActive') ;
so the call showTabs(tabProdIntroActive..) works in both.
This drives me potty.
I hate Microsoft for letting everyone code badly and get away with it
In this case, this is no fault of MS. document.all is a leftover from IE4 (a time when the equivalent Netscape was nuts, DOM-wise). It is left there for backward-compatibility with legacy scripts. This does have the unfortunate by-product of "letting people get away with it", as you say.
My post #11 shows that it is easy to equip any lingering IE4 document objects your page might come across with a
[blue]getElementById[/blue] method. Use this once, and you can forget about [blue]document.all[/blue] for the rest of the script. Oh and I have seen one or two web sites go through and define the variables at the end of pages to overcome this i.e.VAR tabProdIntroActive = getElementById('tabProdIntroActive') ;
so the call showTabs(tabProdIntroActive..) works in both.
This drives me potty.
That was DHTML's prime design specification.
Assigning your elements to vars, even better arrays, is - I say - a good one. It makes coding easier, and is more efficient (doesn't make repeated use of the cpu-costly,
getElementById). A couple of issues, that may crop up: 1. As IE uses id's as global varNames for elements, you will run into difficulties if you use the same global varName (exact capitalisation) for an element, without using the
[blue]var[/blue] keyword. The upshot of this is that, when using a function to do your initialising, you cannot use the same varName for a global as the element's id unless you have previously declared it as a global at the top of the script (as all good boys & girls do anyway). 2. Some quirky browsers may have a problem with attempts to reference elements before the document has fully loaded. I'm not sure. It's common to have statements like these in a function called onload. But then you lose the chance for the browser to do some work while any images are loading.
Oh yes. To make a function accept either an id string or an object reference - as you are talking about - you could do this:
[blue]function hello(ref)
{
ref = document.getElementById(ref)¦¦ref
....
(browsers 4+)[/blue]
And (this is it, honest)
onMouseOver="style.cursor='hand';"
Looks like you're still under the unfluence of MS Bad Code College :)