[英]JS, only use html. Can I check user browser?
Just use HTML.只需使用 HTML。 Not use JS.
不使用JS。 Can I know about user browser
我可以了解用户浏览器吗
I can know about user browser.我可以了解用户浏览器。 If I use JS.
如果我使用 JS。 I want to control in HTML.
我想控制 HTML。 'PC' browser can't see the button.
“PC”浏览器看不到按钮。 But 'Mobel' browser can see the button.
但是“Mobel”浏览器可以看到该按钮。 Only use HTML.
仅使用 HTML。 Not use JS.
不使用JS。 Can I possible it?
我可以吗?
JS Code: window.javascript
. JS代码:
window.javascript
。 var filter = win32|win64"; if(navigator.platform){ if(0 > filter.indexOf(navigator.platform.toLowerCase())){ alert("Mobile"); }else{ alert("PC"); } } var filter = win32|win64"; if(navigator.platform){ if(0 > filter.indexOf(navigator.platform.toLowerCase())){ alert("Mobile"); }else{ alert("PC"); } }
This code will give you the type of device in此代码将为您提供设备类型
tag of HTML, You can use it in other cases if you want. HTML 的标签,如果需要,您可以在其他情况下使用它。
function detectDeviceType() { if ( navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i) ) { $('#typeOfDevice').text('Type of device is Mobile'); } else { $('#typeOfDevice').text('Type of device is PC'); } }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <form> <input type="button" onclick="detectDeviceType();" value="Find type of my device" /> <p id="typeOfDevice"></p> </form>
Hope this helps.希望这可以帮助。
Pure HTML does not have any "active" elements that could be used to check the currently running browser and HTML does not know how it will be displayed/used - that depends on the browser.纯 HTML 没有任何“活动”元素可用于检查当前正在运行的浏览器,并且 HTML 不知道它将如何显示/使用 - 这取决于浏览器。 You do need JS or some other client-side code to perform the check.
您确实需要 JS 或其他一些客户端代码来执行检查。
Well, if your browser will make request to server, you can know its user agent through headers (without js, making post request, for example).好吧,如果您的浏览器将向服务器发出请求,您可以通过 headers 知道它的用户代理(例如,没有 js,发出 post 请求)。 Here you can see browser detection using user-agent https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
在这里您可以看到使用用户代理https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent的浏览器检测
Must contain:必须包含:
But note that some browsers are lying: Chrome for example reports both as Chrome and Safari.但请注意,有些浏览器在撒谎:例如 Chrome 报告为 Chrome 和 Safari。 So to detect Safari you have to check for the Safari string and the absence of the Chrome string, Chromium often reports itself as Chrome too or Seamonkey sometimes reports itself as Firefox.
因此,要检测 Safari,您必须检查 Safari 字符串和 Chrome 字符串的缺失,Chromium 经常将自己报告为 Chrome,或者 Seamonkey 有时将自己报告为 Z763F7F1AEC350CD1A462Z9D1D5C3C22。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.