What is the best way to detect websocket support using Javascript?

后端 未结 5 1272
慢半拍i
慢半拍i 2020-12-31 04:27

I\'m trying to use Javascript to detect if a web browser supports websockets, but using only feature-based detection, I\'m getting false positives, so I added a user agent t

5条回答
  •  粉色の甜心
    2020-12-31 04:40

    I think the Modernizr library is what you are looking for: http://modernizr.com/

    Once you include the library on your page, you can use a simple check like:

    if(Modernizr.websockets){
        // socket to me baby
    }
    

提交回复
热议问题