2017-02-15 169 views
1

其實我有一些聊天,我想把它放在一個窗口內,我找到了一個例子,但沒有加載窗口內的聊天。Javascript - 如何將索引聊天轉換爲聊天窗口

我的聊天功能完全符合索引。檢查圖像。

老index.ejs代碼(只是聊天):

<html> 
<head> 
      <script src="jquery-3.1.1.js"></script> 
      <script src="app.js"></script> 
      <base href="/"> 
      <title>XXXXXXXXXXXXXXXX</title> 
      <meta ------ /> 
      <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"> 
      <link rel="stylesheet" href="css/app.css"> 
     </head> 
     <body> 
      <div id="view-change-button" class="button" onclick="Payloadxxxxxxx.togglePanel(event, this)"> 
      <img class="option full" src="../img/Chat Button.png"> 
      <img class="option not-full" src="../img/Code Button.png"> 
      </div> 
      <div id="contentParent" class="responsive-columns-wrapper"> 
      <div id="chat-column-holder" class="responsive-column content-column"> 
       <div class="chat-column"> 
       <div id="scrollingChat"></div> 
       <label for="textInput" class="inputOutline"> 
        <input id="textInput" class="input responsive-column" 
        placeholder="Type something" type="text" 
        onkeydown="xxxxxxxxxxxxxxxxPanel.inputKeyDown(event, this)"> 
       </label> 
       </div> 
      </div> 
      <div id="payload-column" class="fixed-column content-column"> 
       <div id="payload-initial-message"> 
       xxxxxxxxxxxxxxxxxxxxxxxxxxxxxOtherDescription. 
       </div> 
       <div id="payload-request" class="payload"></div> 
       <div id="payload-response" class="payload"></div> 
      </div> 
      </div> 

    <script src="js/xxxxx.js"></script> 
    <script src="js/xxxxxxxx.js"></script> 
    <script src="js/xxxxxxxxxx.js"></script> 
    <script src="js/xxxxxxxxxx.js"></script> 
    <script src="js/xxxxxxxxx.js"></script> 
</body> 
</html> 

圖片舊的(我用引導的響應頁面):

網絡最大化

enter image description here

如果我減少或增加的瀏覽器窗口

enter image description here

和新指數與按鈕點擊打開聊天,聊天的所有代碼我把裏面的chat.ejs:

<!DOCTYPE html> 
<html> 
<head> 
    <base href="/"> 
    <title>Web Chat - ITSM</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta property="og:image" content="conversation.svg" /> 
    <meta property="og:title" content="Conversation Chat Simple" /> 
    <meta property="og:description" content="Sample application that shows how to use the Conversation API to identify user intents" /> 
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"> 
    <link rel="stylesheet" href="css/app.css"> 
<meta charset="UTF-8"> 
<title>Title of the document</title> 
    <script 
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"> 
    </script> 
<script type="text/javascript"> 
function open_chatbox() { 
    $('#chat').fadeOut(500); 
    $('#chatBox').fadeIn(1000); 
} 
function closeChat() { 
    $('#chatBox').fadeOut(500); 
    $('#chat').fadeIn(1000); 
} 
</script> 
    <style> 
    #chat 
{ 
position:absolute; 
width:200px; 
height:auto; 
padding:10px; 
background:#088A68; 
color:#EDEDED; 
text-align:center; 
font-family:Cambria; 
font-size:20px; 
bottom:0px; 
right:15px; 
cursor:pointer; 
} 
#chatBox 
{ 
display:none; 
position:absolute; 
width:200px; 
height:300px; 
padding:10px; 
background:#EDEDED; 
color:#FF7700; 
text-align:center; 
font-family:Cambria; 
font-size:20px; 
bottom:0px; 
right:15px; 
cursor:pointer; 
} 
#close 
{ 
position:absolute; 
width:15px; 
height:15px; 
padding:6px 5px 10px 5px; 
text-align:center; 
background:rgba(0,0,0,0.8); 
color:#FF7700; 
font-family:Cambria; 
right:0px;top:0px; 
} </style> 

</head> 

<body> 
<div id="chat" onClick="open_chatbox();"> Chat Now </div> 
<div id="chatBox"><div onclick="closeChat()" id="close">X</div> <br><br><div id="view-change-button" class="button" onclick="PayloadPanel.togglePanel(event, this)"> 
    <img class="option full" src="../img/Chat Button.png"> 
    <img class="option not-full" src="../img/Code Button.png"> 
    </div> 
    <div id="contentParent" class="responsive-columns-wrapper"> 
    <div id="chat-column-holder" class="responsive-column content-column"> 
     <div class="chat-column"> 
     <div id="scrollingChat"></div> 
     <label for="textInput" class="inputOutline"> 
      <input id="textInput" class="input responsive-column" 
      placeholder="Type something" type="text" 
      onkeydown="ConversationPanel.inputKeyDown(event, this)"> 
     </label> 
     </div> 
    </div> 

    </div> 
    </div> 
    <script src="js/common.js"></script> 
    <script src="js/api.js"></script> 
    <script src="js/conversation.js"></script> 
    <script src="js/global.js"></script> 
</body> 

</html> 

我看到that的例子。

和錯誤是:

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/ . Uncaught TypeError: Cannot read property 'classList' of null at displayPayload (eval at (jquery.min.js:2), :80:23) at Object.Api.setRequestPayload (eval at (jquery.min.js:2), :52:7) at Object.sendRequest (eval at (jquery.min.js:2), :55:11) at geoSuccess (eval at (jquery.min.js:2), :47:9) displayPayload @ VM901:80 Api.setRequestPayload @ VM901:52 sendRequest @ VM899:55 geoSuccess @ VM900:47 VM901:80 Uncaught TypeError: Cannot read property 'classList' of null at displayPayload (eval at (jquery.min.js:2), :80:23)

實驗值:舊文件index.ejs是新chat.ejs加載聊天窗口內,如果單擊按鈕。

我試着看其他崗位與相同的例子,但他們沒有試圖和我一樣

回答

0

在我把所有.css風格我的CS​​S在倉庫裏的情況下,我加入了scripts srcindex內。之後,工作正常。我並不需要chat.ejs和我插入索引中的所有代碼只是用我的倉庫裏的.css public/css/app.css

校驗碼:

<!DOCTYPE html> 
<html> 
<head> 
    <base href="/"> 
    <title>Web Chat - ITSM</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta property="og:image" content="conversation.svg" /> 
    <meta property="og:title" content="Conversation Chat Simple" /> 
    <meta property="og:description" content="Sample application that shows how to use the Conversation API to identify user intents" /> 
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"> 
    <link rel="stylesheet" href="css/app.css"> 
<meta charset="UTF-8"> 
<title>Title of the document</title> 
    <script 
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"> 
    </script> 
<script type="text/javascript"> 
function open_chatbox() { 
    $('#chat').fadeOut(500); 
    $('#chatBox').fadeIn(1000); 
} 
function closeChat() { 
    $('#chatBox').fadeOut(500); 
    $('#chat').fadeIn(1000); 
} 
</script> 

</head> 

<body> 
<div id="chat" onClick="open_chatbox();"> Chat Now </div> 
<div id="chatBox"><div onclick="closeChat()" id="close">X</div> <br><br><div id="view-change-button" class="button" onclick="PayloadPanel.togglePanel(event, this)"> 
    <img class="option full" src="../img/Chat Button.png"> 
    <img class="option not-full" src="../img/Code Button.png"> 
    </div> 
    <div id="contentParent" class="responsive-columns-wrapper"> 
    <div id="chat-column-holder" class="responsive-column content-column"> 
     <div class="chat-column"> 
     <div id="scrollingChat"></div> 
     <label for="textInput" class="inputOutline"> 
      <input id="textInput" class="input responsive-column" 
      placeholder="Digite algo" type="text" 
      onkeydown="ConversationPanel.inputKeyDown(event, this)"> 
     </label> 
     </div> 
    </div> 

    </div> 
    </div> 
    <script src="js/common.js"></script> 
    <script src="js/api.js"></script> 
    <script src="js/conversation.js"></script> 
    <script src="js/global.js"></script> 
</body> 

</html>