para los expertos en javascript...
Buenas,
aqui estoy de nuevo con otro problemo.
yo de javascript ni zorra, en este campo soy de google-copy-paste y listo, hasta que me decida a entenderlo un poco.
A lo que ibamos, que he metido dos javascripts en una web, y se ve que una de alguna forma anula a la otra, y como no soy capaz de entender el codigo, no se donde coñe puede estar el fallo.
aqui van los codigos:
Este primer codigo es para crear un menu "popup" que en principio funcionaba en todos los navegadores (probado) y que tira de css:
<code>
startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
}
node.onmouseout=function() {
this.className=this.className.replace(" over", "");
}
}
}
}
}
window.onload=startList;
</code>
Funcionaba perfectamente hasta que decidi meterle este otro codigo que es un switch para cambiar estilos css en un solo click :)
(en Firefox sigue funcionando perfectamente, donde no chuta es en Explorer)
<code>function setActiveStyleSheet(title) {
var i, a, main;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
a.disabled = true;
if(a.getAttribute("title") == title) a.disabled = false;
}
}
}
function getActiveStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
}
return null;
}
function getPreferredStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1
&& a.getAttribute("rel").indexOf("alt") == -1
&& a.getAttribute("title")
) return a.getAttribute("title");
}
return null;
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
window.onload = function(e) {
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
}
window.onunload = function(e) {
var title = getActiveStyleSheet();
createCookie("style", title, 365);
}
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
</code>
A ver si alguien puede echarme una mano y decirme donde esta la incompatibilidad y si se puede remendar. ;)
omar
Soy incapaz de leerme todo tu mail, pero intentare ayudarte.
A primera vista te puedo decir q tienes dos eventos ONLOAD definidos, con lo q uno reemplaza a otro:
<code>
window.onload=startList;
</code>
y
<code>
window.onload = function(e) {
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
}
</code>
La solucion, tambien a priori, podira ser:
<code>
window.onload = function(e) {
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
startList();
}
</code>
hipster
gracias omar, pero parece que se ha solucionado simplemente cambiando el orden de las llamadas a los .js, el que estaba primero lo he puesto segundo y viceversa, y funcionan los dos, tanto en firefox como explorer.
aun lo estoy comprobando, pero si viera que me da algun otro error probare con lo que me dices y ya te contare.
gracias ;)