Advertisement
Guest User

Untitled

a guest
Apr 25th, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. Enter Chat and press enter
  2. <div><input id=input placeholder=you-chat-here /></div>
  3.  
  4. Chat Output
  5. <div id=box></div>
  6.  
  7. <script src=http://cdn.pubnub.com/pubnub.min.js></script>
  8. <script>(function(){
  9. var box = PUBNUB.$('box'), input = PUBNUB.$('input'), channel = 'chat';
  10. PUBNUB.subscribe({
  11. channel : channel,
  12. callback : function(text) { box.innerHTML = (''+text).replace( /[<>]/g, '' ) + '<br>' + box.innerHTML }
  13. });
  14. PUBNUB.bind( 'keyup', input, function(e) {
  15. (e.keyCode || e.charCode) === 13 && PUBNUB.publish({
  16. channel : channel, message : input.value, x : (input.value='')
  17. })
  18. } )
  19. })()</script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement