Code Module | کد ماژول
1.93K subscribers
357 photos
42 videos
6 files
356 links
Hello World 🌎

<> Earth is programmable if you code it </>

Group 👇🏻
@CodeModuleGap

Contact Us 👇🏻
@MrShahiin
@neoMahan
Download Telegram
با استفاده از navigator در جاوااسکریپت، چه کارهایی میتونیم انجام بدیم؟ 🪐

تشخیص نوع دستگاه و سیستم‌عامل کاربر:

با استفاده از navigator.userAgent می‌تونیم نوع دستگاه و سیستم‌عامل کاربر رو تشخیص، و محتوای سایت یا اپلیکیشن رو بر اساس اون تنظیم کنیم.
const userAgent = navigator.userAgent.toLowerCase();
if (userAgent.includes('iphone')) {
console.log('User is on an iPhone');
} else if (userAgent.includes('android')) {
console.log('User is on an Android device');
}


دسترسی به اطلاعات شبکه (Network Information API):

از navigator.connection میتونین برای دریافت اطلاعات شبکه کاربر مثل نوع ارتباط (WiFi, 4G) و سرعت اون استفاده کنیم.
const connection = navigator.connection  navigator.mozConnection  navigator.webkitConnection;
if (connection) {
console.log('Effective connection type:', connection.effectiveType);
console.log('Downlink speed:', connection.downlink, 'Mbps');
}


تشخیص وضعیت آنلاین/آفلاین بودن کاربر:

با استفاده از navigator.onLine می‌تونیم وضعیت آنلاین یا آفلاین بودن کاربر رو بررسی کنیم و تجربه کاربری رو بهبود ببخشیم.
if (navigator.onLine) {
console.log('User is online');
} else {
console.log('User is offline');
}


استفاده از Web Share API برای به اشتراک گذاری محتوا:

با استفاده از navigator.share می‌تونیم امکان اشتراک‌گذاری محتوا رو در دستگاه‌های موبایل فراهم کنیم.
const shareData = {
title: 'Example Page',
text: 'Check out this cool page!',
url: 'https://example.com'
};

navigator.share(shareData).then(() => {
console.log('Content shared successfully');
}).catch(err => {
console.error('Error sharing content:', err);
});


دسترسی به باتری دستگاه (Battery Status API):

با استفاده از navigator.getBattery می‌تونیم اطلاعاتی مثل سطح باتری و وضعیت شارژ رو دریافت کنید.
avigator.getBattery().then(battery => {
console.log('Battery level:', battery.level * 100 + '%');
console.log('Charging:', battery.charging ? 'Yes' : 'No');
});


#navigator #javascript
@CodeModule
Please open Telegram to view this post
VIEW IN TELEGRAM
👌43🔥7❤‍🔥4💔4