2016-10-09 6 views
-2

facebook type multiply 채팅 상자를 표시하는 스크립트를 수집합니다. 이 자바 스크립트 코드에서는 Iframe을 사용하여 채팅 페이지를로드했습니다. 하지만 이제 iframe을 피하고 싶습니다. 자바 스크립트에 대한 충분한 지식이 없습니다.jquery로 jquery가 전송되지 않음

이 스크립트를 위해 JavaScript로 내 채팅 페이지를로드하는 방법이 있습니다. 또는 jquery에서이 스크립트를 전송하면 어디에서 문제가 발생합니까?

자바 스크립트 :

function register_popup(id, name, cmd, pmd) 
     { 
      for(var iii = 0; iii < popups.length; iii++) 
      { 
       //already registered. Bring it to front. 
       if(id == popups[iii]) 
       { 
        Array.remove(popups, iii); 
        popups.unshift(id); 
        calculate_popups(); 
        return; 
       } 
      } 
     var element = '<div class="popup-box chat-popup cy'+id+'" id="'+ id +'">'; 
     //if avoid iframe how to load chat page 
     element = element + '<div class="popup-messages"><iframe src="../chat.php?u='+ cmd +'" frameborder="0" id="iFrame1" name="CmainFrame" width="100%" height="249" style="overflow:hidden" class="if'+ cmd +'"></div></div>'; 
     document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML + element; 
      popups.unshift(id); 
      calculate_popups(); 
     } 

function calculate_popups() 
     { 
      var width = window.innerWidth; 
      if(width < 540) 
      { 
       total_popups = 0; 
      } 
      else 
      { 
       width = width - 200; 
       //320 is width of a single popup box 
       total_popups = parseInt(width/320); 
      } 
      display_popups(); 
     } 

function display_popups() 
     { 
      var right = 220; 
      var iii = 0; 
      for(iii; iii < total_popups; iii++) 
      { 
       if(popups[iii] != undefined) 
       { 
        var element = document.getElementById(popups[iii]); 
        element.style.right = right + "px"; 
        right = right + 320; 
        element.style.display = "block"; 
       } 
      } 
      for(var jjj = iii; jjj < popups.length; jjj++) 
      { 
       var element = document.getElementById(popups[jjj]); 
       element.style.display = "none"; 
      } 
     } 
     //recalculate when window is loaded and also when window is resized. 
     window.addEventListener("resize", calculate_popups); 
     window.addEventListener("load", calculate_popups); 

//this function can remove a array element. 
Array.remove = function(array, from, to) { 
      var rest = array.slice((to || from) + 1 || array.length); 
      array.length = from < 0 ? array.length + from : from; 
      return array.push.apply(array, rest); 
}; 

가 JQuery와 같은 시도 : 나는 밀접하게 코드를 분석하지 않았다

function register_popup(id, name, cmd, pmd) 
     { 
      for(var iii = 0; iii < popups.length; iii++) 
      { 
       //already registered. Bring it to front. 
       if(id == popups[iii]) 
       { 
        Array.remove(popups, iii); 
        popups.unshift(id); 
        calculate_popups(); //alert(popups(id)); 
        return; 
       } 
      } 
     $("<div></div>").attr('id',id).append('<div class="popup-box chat-popup cy'+id+'" id="'+ id +'"><div class="popup-messages"><div id="iFrame1" name="CmainFrame" width="100%" height="249" style="overflow:hidden" class="if'+ cmd +'"><object type="text/html" data="../chat.php?u='+ cmd +'"></div></div></div>'); 
      popups.unshift(id); 
      calculate_popups(); 
     } 

function display_popups() 
     { 
      var right = 220; 
      var iii = 0; 
      for(iii; iii < total_popups; iii++) 
      { 
       if(popups[iii] != undefined) 
       { 
        right = 220 + 320; 
        $("#"+popups[iii]).css({"display": "block", "right": "right"}).show(); 
       } 
      } 
      for(var jjj = iii; jjj < popups.length; jjj++) 
      { 
       $("#"+popups[jjj]).css("display", "none"); 
      } 
     } 
//others function remain same 
+2

글쎄, 어떻게하면 어떻게됩니까? – Malvolio

+0

표시 없음 ... – koc

+1

표시 할 이유가 표시되지 않습니다. DOM에 아무 것도 추가하지 마십시오. – Malvolio

답변

0

,하지만이 통지 않았다

$("<div></div>").attr('id',id).append('<div class="popup-box chat-popup cy'+id+'" id="'+ id +'"><div class="popup-messages"><div id="iFrame1" name="CmainFrame" width="100%" height="249" style="overflow:hidden" class="if'+ cmd +'"><object type="text/html" data="../Cchat.php?u='+ cmd +'"></div></div></div>'); 

그렇게하지 당신이 무엇을 알고 있는지 이 할 일은라고 생각합니다.하지만 그 일은 div를 생성하는 것입니다. 이드에게 신원을 밝히고, 일부 아이들에게주고, 모든 것을 던지십시오. 어딘가에 넣고 싶니?

편집 :

예를 들어, 당신이 쓸 수 :

$("body").append('<div class="popup-box chat-popup cy'+id+'"... 

(. 몸을 찾아 그 아래에 새로운 사업부에 삽입)

또는

$("#" + id).append('<div class="popup-box chat-popup cy'+id+'"... 

(지정된 ID가있는 기존 div 찾기 t 그는 그것에 새로운 div.)

+0

$ ("body"). append (작동 중 ... – koc

관련 문제