© Khmer Angkor Academy - sophearithput168

BOM (Browser Object Model)

សេចក្តីផ្តើម

BOM (Browser Object Model) អនុញ្ញាតឱ្យ JavaScript ទំនាក់ទំនងជាមួយ browser។ វាផ្តល់នូវ objects ដូចជា window, navigator, screen, location, និង history។

BOM Objects

Objectការពិពណ៌នាឧទាហរណ៍
windowBrowser windowwindow.innerWidth
navigatorBrowser infonavigator.userAgent
screenScreen infoscreen.width
locationURL infolocation.href
historyBrowser historyhistory.back()

Window Object

window.innerWidth   // Width
window.innerHeight  // Height
window.open()       // Open new window
window.close()      // Close window

Object មេនៃ browser


Navigator Object

navigator.userAgent     // Browser info
navigator.platform      // Platform
navigator.language      // Language
navigator.onLine        // Online status

ព័ត៌មានអំពី browser


Screen Object

screen.width           // Screen width
screen.height          // Screen height
screen.availWidth      // Available width
screen.availHeight     // Available height
screen.colorDepth      // Color depth

ព័ត៌មានអំពី screen


Location Object

location.href          // Full URL
location.hostname      // Domain name
location.pathname      // Path
location.protocol      // Protocol (http:)
location.reload()      // Reload page

ព័ត៌មានអំពី URL


History Object

history.back()         // Go back
history.forward()      // Go forward
history.go(-2)         // Go back 2 pages
history.length         // History length

គ្រប់គ្រង browser history


Alert, Confirm, Prompt

alert("Message");
let result = confirm("Are you sure?");
let name = prompt("Enter name:");

Dialog boxes របស់ browser


Best Practices

  • ប្រើ BOM សម្រាប់ browser-specific tasks
  • ពិនិត្យ browser compatibility
  • ប្រើ feature detection ជំនួស browser detection
  • ជៀសវាង window.open() popup blockers

សង្ខេប

  • BOM ផ្តល់ browser functionality
  • window - Browser window object
  • navigator - Browser information
  • screen - Screen properties
  • location - URL manipulation
  • history - Navigation control