Ver Mensaje Individual
  #5 (permalink)  
Antiguo 20/02/2012, 13:24
Avatar de Panino5001
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: Abrir ventana (no pop-up) desde AJAX

Para abrir un popup de esa manera y que no sea bloqueado, lo que hay que hacer es abrir la ventana durante el onclick, aunque esté vacía. Luego, una vez obtenida la respuesta ajax, podemos escribir la misma en la ventana abierta (o cerrarla si es necesario):
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<
title>Documento sin título</title>
<
script>
function 
http(){
    if(
typeof window.XMLHttpRequest!='undefined'){
        return new 
XMLHttpRequest();    
    }else{
        try{
            return new 
ActiveXObject('Microsoft.XMLHTTP');
        }catch(
e){
            
alert('Su navegador no soporta AJAX');
            return 
false;
        }    
    }    
}
function 
request(url,callback,params){
    var 
H=new http();
    if(!
H)return;
    
H.open('post',url+'?'+Math.random(),true);
    
H.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    
H.onreadystatechange=function(){
        if(
H.readyState==4){
            
callback(H.responseText);
            
H.onreadystatechange=function(){}
            
H.abort();
            
H=null;
        }
    }
    var 
p='';
    for(var 
i in params){
        
p+='&'+i+'='+escape(params[i]);    
    }
    
H.send(p);
}
function 
abrir(){
    var 
a=window.open('','','width=500,height=500');
    
request('uno.html',function(r){
            
a.document.open();
            
a.document.write(r);
            
a.document.close();
    },{})
}
</script>
</head>

<body>
<div style="width:150px; border:1px solid #000; background:orange; text-align:center; line-height:30px; cursor:pointer" onclick="abrir()">abrir</div>
</body>
</html> 
Si en uno.html tenemos escrito:
Código PHP:
<h1>Hola</h1
Aparecerá ese hola escrito en la ventana secundaria.
Otra alternativa es usar ventanas tipo lightbox.


Ahora, algo más parecido a lo que decís necesitar. Imaginate que en uno.html dice esto:
Código PHP:
http://forosdelweb.com 
Si lo que necesitás es redirigir a esa url obtenida vía AJAX, con esto bastaría:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<
title>Documento sin título</title>
<
script>
function 
http(){
    if(
typeof window.XMLHttpRequest!='undefined'){
        return new 
XMLHttpRequest();    
    }else{
        try{
            return new 
ActiveXObject('Microsoft.XMLHTTP');
        }catch(
e){
            
alert('Su navegador no soporta AJAX');
            return 
false;
        }    
    }    
}
function 
request(url,callback,params){
    var 
H=new http();
    if(!
H)return;
    
H.open('post',url+'?'+Math.random(),true);
    
H.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    
H.onreadystatechange=function(){
        if(
H.readyState==4){
            
callback(H.responseText);
            
H.onreadystatechange=function(){}
            
H.abort();
            
H=null;
        }
    }
    var 
p='';
    for(var 
i in params){
        
p+='&'+i+'='+escape(params[i]);    
    }
    
H.send(p);
}
function 
abrir(){
    var 
a=window.open('','','width=500,height=500');
    
request('uno.html',function(r){
            
a.location=r;
    },{})
}
</script>
</head>

<body>
<div style="width:150px; border:1px solid #000; background:orange; text-align:center; line-height:30px; cursor:pointer" onclick="abrir()">abrir</div>
</body>
</html> 

Última edición por Panino5001; 20/02/2012 a las 13:35