Untuk mendapatkan maklumat tentang penyemak imbas halaman web sedang dijalankan, gunakan objek navigator terbina dalam. Anda boleh menggunakan pelbagai kaedah dan sifat Navigator pada objek ini.
Anda boleh cuba jalankan kod berikut untuk melaksanakan objek Navigator dalam JavaScript -
<html> <head> <title>Navigator Object Example</title> </head> <body> <script> <!-- var userAgent = navigator.userAgent; var opera = (userAgent.indexOf('Opera') != -1); var ie = (userAgent.indexOf('MSIE') != -1); var gecko = (userAgent.indexOf('Gecko') != -1); var netscape = (userAgent.indexOf('Mozilla') != -1); var version = navigator.appVersion; if (opera) { document.write("Opera based browser"); // Keep your opera specific URL here. } else if (gecko) { document.write("Mozilla based browser"); // Keep your gecko specific URL here. } else if (ie) { document.write("IE based browser"); // Keep your IE specific URL here. } else if (netscape) { document.write("Netscape based browser"); // Keep your Netscape specific URL here. } else { document.write("Unknown browser"); } // You can include version to along with any above condition. document.write("<br /> Browser version info : " + version ); //--> </script> </body> </html>
Atas ialah kandungan terperinci Apakah peranan objek Navigator dalam JavaScript?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!