Edgeも考慮した時のブラウザ判定
以前、IE11, Edge の対応をした際にこんな記事を書き残していたけれど、
Microsoft Edge の場合は UA に Chrome, Safari, AppleWebkit という文字列も含まれる。
次のように先に IE の判定が出来ればよいが、
if /MSIE|Trident|Edge/ ... else if /Firefox/ ... else if /Chrome/ ... else ... end
例えば firefox であるか。chrome であるかのみ判定したい場合はこんな風にするんだろうか。
// firefox window.navigator.userAgent.indexOf('Firefox') >= 0 && window.navigator.userAgent.indexOf('Edge') == -1 // chrome window.navigator.userAgent.indexOf('Chrome') >= 0 && window.navigator.userAgent.indexOf('Edge') == -1
# firefox ua =~ /firefox/i && ua !~ /edge/i # chrome ua =~ /chrome/i && ua !~ /edge/i