I was told this was supposed to work in Chrome, but the check always results as false
.
Here is my code:
if("Websocket" in window){
Echo.socket = new WebSocket(host);
} else if("MozWebsocket" in window) {
Echo.socket = new MozWebSocket(host);
} else {
console.log("Error: websocket is not supported by this browser");
return;
}
I always get the Error: websocket...
in the console. Why?
Your capitalization of the words "Websocket"
and "MozWebsocket"
is wrong. You need a capital letter S
for socket.
You need to check for "WebSocket"
and "MozWebSocket"
in window
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.