How to determine the Opera browser using JavaScript

后端 未结 6 919
清歌不尽
清歌不尽 2020-12-14 17:09

I want to determine that the browser of the client machines in Opera or not using JavaScript, how to do that?

6条回答
  •  醉酒成梦
    2020-12-14 17:49

    Now that Opera uses the Chrome rendering engine, the accepted solution no longer works.

    The User Agent string shows up like this:

    Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36 OPR/15.0.1147.132

    The only identifier for Opera is the OPR part.

    Here's the code I use, which should match the old Opera or the new Opera. It makes the Opera var a boolean value (true or false):

    var Opera = (navigator.userAgent.match(/Opera|OPR\//) ? true : false);

提交回复
热议问题