screen_rotation
Copied to Clipboard
<html> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <div> <h1>Vue js Detect the Operating System of User </h1> <p>Operating System: {{ os }}</p> </div> </div> <script type="module"> const app = new Vue({ el: "#app", data: { os: '' }, mounted() { this.os = this.detectOS(); }, methods: { detectOS() { const platform = navigator.platform; if (platform.indexOf('Win') !== -1) return 'Windows'; if (platform.indexOf('Mac') !== -1) return 'Mac OS'; if (platform.indexOf('Linux') !== -1) return 'Linux'; return 'Unknown'; } } }); </script> </body> </html>