Foros del Web » Programando para Internet » Javascript »

Ayuda con Window.Onload por favor

Estas en el tema de Ayuda con Window.Onload por favor en el foro de Javascript en Foros del Web. Hola, espero alguien pueda ayudarme porque de verdad tengo un dia perdido tratando de solucionar este problema y ya como ultima opcion tengo por recurrir ...
  #1 (permalink)  
Antiguo 22/10/2010, 19:48
 
Fecha de Ingreso: octubre-2007
Mensajes: 22
Antigüedad: 16 años, 6 meses
Puntos: 0
Pregunta Ayuda con Window.Onload por favor

Hola,

espero alguien pueda ayudarme porque de verdad tengo un dia perdido tratando de solucionar este problema y ya como ultima opcion tengo por recurrir a la ayuda de ustedes foreros

El problema es que estoy usando 2 Scripts distintos que usan el evento Window.Onload y pues obvio solo me funciona o el uno o el otro pero nunca los 2 juntos.

El primer Script es para el Resize de Un iframe que tengo (el unico que me ha funcionado sin problemas y que no puedo cambiar), el cual consiste en esto:

Código:
<script language="Javascript"> 
function getWindowData(n,i){
    var ifr=document.getElementById(i).contentWindow.document || document.getElementById(i).contentDocument;
    var widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal;
    if (typeof window.frames[n].innerWidth != 'undefined'){
        widthViewport= window.frames[n].innerWidth;
        heightViewport= window.frames[n].innerHeight;
    }else if(typeof ifr.documentElement != 'undefined' && typeof ifr.documentElement.clientWidth !='undefined' && ifr.documentElement.clientWidth != 0){
        widthViewport=ifr.documentElement.clientWidth;
        heightViewport=ifr.documentElement.clientHeight;
    }else{
        widthViewport= ifr.getElementsByTagName('body')[0].clientWidth;
        heightViewport=ifr.getElementsByTagName('body')[0].clientHeight;
    }
    xScroll=window.frames[n].pageXOffset || (ifr.documentElement.scrollLeft+ifr.body.scrollLeft);
    yScroll=window.frames[n].pageYOffset || (ifr.documentElement.scrollTop+ifr.body.scrollTop);
    widthTotal=Math.max(ifr.documentElement.scrollWidth,ifr.body.scrollWidth,widthViewport);
    heightTotal=Math.max(ifr.documentElement.scrollHeight,ifr.body.scrollHeight,heightViewport);
    return [widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal];
} 
function resizeIframe(ID,NOMBRE){
document.getElementById(ID).height=null;
document.getElementById(ID).width=null;
window.location='#';//necesario para safari
var m=getWindowData(NOMBRE,ID); 
document.getElementById(ID).height=m[5];
document.getElementById(ID).width=m[4]+22;
} 
function addEvent(obj, evType, fn, useCapture){

if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    
  } else if (obj.attachEvent){
    obj.attachEvent("on"+evType, fn);
   
  } else {
   obj['on'+evType]=fn;
  }
}
window.onload=function(){
    resizeIframe('iframe','iframe');
    addEvent(document.getElementById('iframe'), 'load', function(){resizeIframe('iframe','iframe');}, false);
}

</script>


Y Pues el segundo Script consiste en cambiar dinamicamente la imagen de fondo de mi web luego de unos segundos :

Código:
<script type="text/javascript">
var fondos = ["imagenes/fondook.jpg", "imagenes/fondook2.jpg", "imagenes/fondook3.jpg"];
var actual = 0;
window.onload = function() {
setInterval("document.body.style.backgroundImage = 'url(' + fondos[actual++ % fondos.length] + ')'", 9000);
}
</script>


De verdad quisiera que alguien me pudiera ayudar, estuve viendo algunos temas similares donde postean algunas soluciones pero de verdad no se como implementarlas Ayuda pleasee!
  #2 (permalink)  
Antiguo 22/10/2010, 20:51
Avatar de Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Respuesta: Ayuda con Window.Onload por favor

Usa la solución de Simon Willison:
http://simonwillison.net/2004/May/26/addLoadEvent/

De esa manera, en lugar de:
Código PHP:
//esto no funcionará
window.onload=algo;
window.onload=otro
Podrás usar:
Código PHP:
//esto funcionará:
addLoadEvent(algo);
addLoadEvent(otro); 
Y si no querés usar esto, bastaría con:
Código PHP:
//esto funcionará:
window.onload=function(){algo();otro();} 
En tu caso:
Código PHP:
var fondos = ["imagenes/fondook.jpg""imagenes/fondook2.jpg""imagenes/fondook3.jpg"];
var 
actual 0;

window.onload=function(){
    
resizeIframe('iframe','iframe');
    
addEvent(document.getElementById('iframe'), 'load', function(){resizeIframe('iframe','iframe');}, false);
    
setInterval("document.body.style.backgroundImage = 'url(' + fondos[actual++ % fondos.length] + ')'"9000);


  #3 (permalink)  
Antiguo 22/10/2010, 23:43
 
Fecha de Ingreso: octubre-2007
Mensajes: 22
Antigüedad: 16 años, 6 meses
Puntos: 0
Respuesta: Ayuda con Window.Onload por favor

Por Dios me siento estupida, perdí TODO un día tratando de resolver lo que tu hiciste en unos pocos minutos! pero bueno por eso es que se lo dejo a los expertos!!

Muchas Graciaaaas!!!! gracias por tomarte el tiempo de ayudarme, al fin lo he conseguido! y ya me funcionan los 2 scripts perfectamente
  #4 (permalink)  
Antiguo 23/10/2010, 00:27
Avatar de Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Respuesta: Ayuda con Window.Onload por favor

Me alegra que hayas resuelto el problema. No te sientas mal: a todos nos pasó (y nos seguirá pasando) perder tiempo con cosas así.
  #5 (permalink)  
Antiguo 23/12/2011, 14:49
 
Fecha de Ingreso: octubre-2006
Mensajes: 128
Antigüedad: 17 años, 6 meses
Puntos: 0
Respuesta: Ayuda con Window.Onload por favor

podrias ayudarme con este es el mismo problema no se como agregar las dos funciones
Cita:
function get_xmlhttp() {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp
}
function probar_XMLHttpRequest(merchId,storeId,termId,currI d) {
xmlhttp=get_xmlhttp()
var monto = document.getElementById("monto").value;
var order = document.getElementById("order").value;

xmlhttp.open("GET", "calculaDigest.php?monto="+monto+"&order="+order+" &merchId="+merchId+"&storeId="+storeId+"&termId="+ termId+"&currId="+currId,false);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4)
var serverResponse = xmlhttp.responseText;
document.getElementById("vdig").innerHTML=serverRe sponse;
document.getElementById("digest").value=serverResp onse;
};
xmlhttp.send(null);
}

Etiquetas: favor
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Tema Cerrado




La zona horaria es GMT -6. Ahora son las 21:45.