[英]JS to detect safari desktop not mobile
我正在嘗試根據特定規則顯示不同的文本。 這就是我需要實現的目標。
如果訪客在:
桌面=顯示消息1
桌面但使用safari =顯示消息2(不是消息1)
移動=顯示消息3
移動和使用safari(顯示消息3. NOT消息2)
我正在走的路線是這個,但我真的不是程序員,除了檢測用戶是否在野生動物園,我有點卡住了! 它需要在桌面上的safari上顯示,但在safari移動設備上顯示不同的消息。 我看了看論壇,但沒有什么太相似的東西跳出來,所以我真的很感激任何幫助!:
<script type="text/javascript">
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1)
{document.writeln("<p>You're using safari!</p>");}
非常感謝!
您可以使用相同的navigator
對象。
如果以模擬模式加載應用程序並運行navigator.userAgent
你可能會看到這個
Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/46.0.2490.76 Mobile Safari/537.36"
與“ 移動 ”一詞相匹配可以幫助您了解它是桌面還是瀏覽器
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.