socket.io提供了针对各个版本浏览器的‘socket’功能的封转:websocket,长连接,流,flash什么的。给你格式化下代码:
if (/Firefox\/\s/.test(navigator.userAgent)){ var socket = io.connect('127.0.0.1:8000',{ transports:['xhr-polling']}); } else if (/MSIE (\d+.\d+);/.test(navigator.userAgent)){ var socket = io.connect('127.0.0.1:8000',{ transports:['jsonp-polling']}); } else { var socket = io.connect('127.0.0.1:8000'); }