Skip to content

[javascript] 利用瀏覽器特性判斷瀏覽器類別

Published: at 01:06 PM

許多人使用 http 請求的 header 中 user-agent 這個欄位來判斷瀏覽器,但在許多程式及APP,其實都內建修改 user-agent 的方法。

這邊記錄一下使用 duck typing 來判斷瀏覽器的方法,而不以輕易被偽造的 user-agent 判斷。

每個瀏覽器都有一些內建的方法或特性可以判斷

參考資料:

http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser