Ver Mensaje Individual
  #2 (permalink)  
Antiguo 28/08/2012, 06:02
mario8
 
Fecha de Ingreso: agosto-2012
Mensajes: 12
Antigüedad: 11 años, 8 meses
Puntos: 0
Respuesta: Duda con javascript en chat

Código Javascript:
Ver original
  1. function startChatSession(){  
  2.     $.ajax({
  3.       url: "chat.php?action=startchatsession",
  4.       cache: false,
  5.       dataType: "json",
  6.       success: function(data) {
  7.  
  8.         username = data.username;
  9.  
  10.         $.each(data.items, function(i,item){
  11.             if (item)   { // fix strange ie bug
  12.  
  13.                 chatboxtitle = item.f;
  14.  
  15.                 if ($("#chatbox_"+chatboxtitle).length <= 0) {
  16.                     createChatBox(chatboxtitle,1);
  17.                 }
  18.                
  19.                 if (item.s == 1) {
  20.                     item.f = username;
  21.                 }
  22.  
  23.                 if (item.s == 2) {
  24.                     $("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxinfo">'+item.m+'</span></div>');
  25.                 } else {
  26.                     $("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom">'+item.f+':&nbsp;&nbsp;</span><span class="chatboxmessagecontent">'+item.m+'</span></div>');
  27.                 }
  28.             }
  29.         });
  30.        
  31.         for (i=0;i<chatBoxes.length;i++) {
  32.             chatboxtitle = chatBoxes[i];
  33.             $("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);
  34.             setTimeout('$("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);', 100); // yet another strange ie bug
  35.         }
  36.    
  37.     setTimeout('chatHeartbeat();',chatHeartbeatTime);
  38.        
  39.     }});
  40. }
  41.  
  42.  
  43. jQuery.cookie = function(name, value, options) {
  44.     if (typeof value != 'undefined') { // name and value given, set cookie
  45.         options = options || {};
  46.         if (value === null) {
  47.             value = '';
  48.             options.expires = -1;
  49.         }
  50.         var expires = '';
  51.         if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
  52.             var date;
  53.             if (typeof options.expires == 'number') {
  54.                 date = new Date();
  55.                 date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
  56.             } else {
  57.                 date = options.expires;
  58.             }
  59.             expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
  60.         }
  61.         // CAUTION: Needed to parenthesize options.path and options.domain
  62.         // in the following expressions, otherwise they evaluate to undefined
  63.         // in the packed version for some reason...
  64.         var path = options.path ? '; path=' + (options.path) : '';
  65.         var domain = options.domain ? '; domain=' + (options.domain) : '';
  66.         var secure = options.secure ? '; secure' : '';
  67.         document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  68.     } else { // only name given, get cookie
  69.         var cookieValue = null;
  70.         if (document.cookie && document.cookie != '') {
  71.             var cookies = document.cookie.split(';');
  72.             for (var i = 0; i < cookies.length; i++) {
  73.                 var cookie = jQuery.trim(cookies[i]);
  74.                 // Does this cookie string begin with the name we want?
  75.                 if (cookie.substring(0, name.length + 1) == (name + '=')) {
  76.                     cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  77.                     break;
  78.                 }
  79.             }
  80.         }
  81.         return cookieValue;
  82.     }
  83. };
No entro todo en un mensaje lo siento, ando un poco perdido pero me entiendo gracias a un amigo que me enseño este foro. un saludo y gracias de antemano.