• Bannato Super User

    Messaggeria privata script

    Salve allora vi pongo un problem ho bisogno che all'arrivo di un msg privato si apra una window in js in modo automatico.

    Avevo pensato ad una richiesta in js ad un file .php ogni tot secondi in tutte le pagine del portale ( penso che sia ajax ) e se il file .php restituisce un valore maggiore di 0 ( ovvero ci sono nuovi messaggi ) si apre la classica window in js con la lista dei messaggi.

    Come posso creare questo sistema?


  • User Attivo

    Ecco la soluzione, visto che io e mix lavoriamo insieme magari può essere utile a qualcuno anche se ho bisogno di un'aiuto per ultimarla:

    var myRequest = null;
    var ciclo = 0;
    
    function CreateXmlHttpReq(handler) {
      var agt = navigator.userAgent.toLowerCase();
      var is_ie5 = (agt.indexOf('msie 5') != -1);
      var xmlhttp = null;
      try {
        xmlhttp = new XMLHttpRequest();
        try {
            // Fix for some version of Mozilla browser.
            http_request.overrideMimeType('text/xml');
        } catch(e) { }
        xmlhttp.onload = handler;
        xmlhttp.onerror = handler;
      } catch(e) {
        var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
        xmlhttp = new ActiveXObject(control);
        xmlhttp.onreadystatechange = handler;
      }
      return xmlhttp;
    }
    
    function myHandler() {
        if (myRequest.readyState == 4 && myRequest.status == 200) {
            if (myRequest.responseText > 0) {
    			var sw,sh;
    			sw=screen.width;
    			sh=screen.height;
    			sw=(sw-500)/2;
    			sh=(sh-550)/2;
    			window.open('Lista_Msg.php','mexpriv','width=500,height=550,resizable=no,scrollbars=yes,left='+sw+',top='+sh);
    			ciclo = 1;
    			}
    	if(ciclo == 0) setTimeout("start()",10000);
        }
    }
    
    function start(Utente) {
        myRequest = CreateXmlHttpReq(myHandler);
        myRequest.open("GET","LettoreMsg.php?user=Utente");
        myRequest.send(null);
    }
    ``` che linka al file php. Per far partire la richiesta uso questo codice nel tag body della pagina ```
    onLoad='setTimeout&#40;"start&#40;'<? echo $_SESSION&#91;'utente'&#93;; ?>'&#41;",10000&#41;;'
    ``` ho qualche problema con gli apici, non riesco a passare la variabile Utente allo script...chi ci può aiutare?!grazie

  • User Newbie

    ciao

    prova con

    onLoad='setTimeout("start('<? echo $_SESSION['utente']; ?>')",10000);'


  • User Newbie

    a proposito.. non sono un esperto di js, sto provando a usare le funzione setInterval() e setTimeOut() per richiamare ogni tot secondi una funzione js, l'unica cosa snervante è che nella barra di stato di firefox ogni volta che viene richiamata la funzione riappare il classico messaggio di ricaricamento della pagina..
    Soluzioni?


  • Consiglio Direttivo

    nel mio sito utilizzo questo in un piccolo frame, ovviamente va lavorato di sessioni:

    [php]<?PHP
    header("Refresh: 60;");
    session_start();
    $nick=$_SESSION['nick'];
    include=;
    $sql="SELECT * FROM posta WHERE destinatario='$nick' AND letto='0'";
    $query = @mysql_query ($sql) or die (mysql_error());
    $ver = mysql_num_rows($query);
    echo "<html><head><title>
    </title></head>
    <body>";
    if ($ver!=0)
    {
    echo '<p align=center><a href=postainarrivo.php target=content2><img border=0 src=pergamena.gif></a></p>';
    }
    echo "</body></html>";
    @mysql_close($connessione);
    ?>[/php]

    Nel mio caso faccio visualizzare un immagine, per fare aprire una nuova pagina (in pop-up mi sembra che intendi), basta variare mettendo l'if nel body per l'OnLoad:

    [php]..........
    echo "<body ";
    if ($ver!=0)
    {
    echo 'OnLoad="javascript:window.open('paginamessaggi.php','Popup','resizable=yes, location=no, menubar=no, toolbar=no, scrollbars=yes, width=740, height=600');"';
    }
    echo '>';

    echo "</body></html>";
    @mysql_close($connessione);
    ?>[/php]
    😉


  • User Attivo

    Ma oggi come oggi non è meglio usare un DIV? almeno non c'è il blocco