狄烁STEC的试验场

hello earth

导航

socket.io 在 ie6 下的问题

下面这个例子在ie6中会报错(socket.io版本0.9.4)

Server:

1 var io = require('socket.io').listen(80);
2
3 io.sockets.on('connection', function (socket) {
4 socket.emit('news', { hello: 'world' });
5 socket.on('my other event', function (data) {
6 console.log(data);
7 });
8 });

Client:

 1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>test</title>
5 </head>
6 <body>
7 <h1>simple test</h1>
8 <p>ie6 socket.io test.</p>
9 <script src="/socket.io/socket.io.js"></script>
10 <script>
11 var socket = io.connect();
12 socket.on('news', function (data) {
13 alert('news');
14 socket.emit('my other event', { my: 'data' });
15 });
16 </script>
17 </body>
18 </html>

Error:

Line: 1629
Char: 9
Error: Objcet does't support this property or method
Code: 0
URL: httl://localhost

这段产生错误的代码如下:

1619 xhr.open('GET', url, true);
1620 xhr.withCredentials = true;
1621 xhr.onreadystatechange = function () {
1622 if (xhr.readyState == 4) {
1623 xhr.onreadystatechange = empty;
1624
1625 if (xhr.status == 200) {
1626 complete(xhr.responseText);
1627 } else {
1628 !self.reconnecting && self.onError(xhr.responseText);
1629 }
1630 }
1630 };
1632 xhr.send(null);

其实引起错误的是1620行.改成如下即可:

try {
xhr.withCredentials = true;
} catch(e) {}

引起错误的原因就是这个属性,时间关系,下次在补充...

posted on 2012-04-01 16:48  狄烁STEC  阅读(1937)  评论(0编辑  收藏  举报