简体   繁体   English

JS,只使用 html。 我可以检查用户浏览器吗?

[英]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:必须包含:

  • Firefox - Firefox/xyz Firefox - 火狐/xyz
  • Chrome - Chrome/xyz铬 - 铬/xyz
  • Chromium Chromium/xyz铬铬/xyz
  • Safari Safari/xyz Safari Safari/xyz
  • Opera - OPR/xyz (Opera 15+) Opera/xyz (Opera 12-) Opera - OPR/xyz (Opera 15+) Opera/xyz (Opera 12-)
  • Internet Explorer -; IE浏览器 -; MSIE xyz; MSIE xyz;

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.

相关问题 HTML。 如何检查用户是否以表格形式输入文字? - HTML. How to check If user entered text in form? 可以在Variable中分配URL地址并在HTML中使用。 使用JavaScript? - Can Assign URL address in Variable and use in HTML. using JavaScript? 在 html 中添加属性时出错。 我该如何解决? - Error with adding an attribute in html. How can i do fix it? 我试图从html中的json获取数据。 我不想使用Ajax,因为 - I am trying to get the data from json in html. I don't want to use Ajax because 我的 Js 文件没有链接到我的 html。我做错了什么? - My Js file is not linking to my html. What am i doing wrong? 如何将字符串转换为HTML。 我希望实际的href显示/显示而不是文字 - how can I convert string into HTML. I want the actual href to show/display instead of the text 我可以为按钮html添加自定义属性吗?它适用于所有浏览器吗? - Can I add custom attributes to button html. Will it work in all browsers 像.load()这样的Ajax函数会从HTML中删除注释。 我该如何保留评论? - Ajax functions like .load() strip out comments from the HTML. How can I keep the comments? 我如何才能使用featherlight.gallery.js不仅以模式显示照片,还以模式显示一些html内容 - How can I use featherlight.gallery.js to display not only photos but some html content in modal, too 我可以在没有 npm 或 node.js 的情况下使用 .dotenv 库作为 HTML 脚本导入吗? - Can I use .dotenv library as HTML script imports only without npm or node.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM