Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Exploring Core BOM Objects for Navigation and Client Information

Tech 2

Location Interface

Direct access to the current document's address bar is provided through the window.location property. This interface exposes methods and attributes for reading protocol information, server addresses, and executing page redirects.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Location API Demo</title>
  <script>
    async function extractUrlData() {
      console.log('Server Host:', window.location.host);
      console.log('Domain Name:', window.location.hostname);
      console.log('TCP Port:', window.location.port);
      console.log('Full Resource URI:', window.location.href);
      
      // Programmatically trigger navigation
      window.location.replace('https://www.google.com');
    }
  </script>
</head>
<body>
  <button id="btn-extract">Extract URL Details</button>
  <script>
    document.getElementById('btn-extract').addEventListener('click', extractUrlData);
  </script>
</body>
</html>

History Interface

The browser session stack is managed via window.history. Developers can traverse past and future visited pages with out relying on native browser controls. This is particularly useful for custom navigation menus or single-page application routing simulations.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>History API Demo</title>
  <script>
    function moveForwardInStack() {
      window.history.forward();
    }

    function moveBackwardInStack() {
      window.history.back();
    }

    function jumpByIndex(delta) {
      window.history.go(delta);
    }

    function setupListeners() {
      document.getElementById('nav-fwd').addEventListener('click', moveForwardInStack);
      document.getElementById('nav-back').addEventListener('click', moveBackwardInStack);
      document.getElementById('nav-jump').addEventListener('click', () => jumpByIndex(2));
    }
    
    window.addEventListener('DOMContentLoaded', setupListeners);
  </script>
</head>
<body>
  <a href="target-page.html" target="_self">Visit Target Page</a>
  <div style="margin-top: 10px;">
    <button id="nav-fwd">Go Forward</button>
    <button id="nav-back">Go Back</button>
    <button id="nav-jump">Jump +2 Entries</button>
  </div>
</body>
</html>

Screen and Navigator Interfaces

While location and history handle navigation flow, screen and navigator provide metadata about the user's hardware display and software environment. These objects are essential for responsive layout adjustments, feature detection, and analytics tracking.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Client Metadata Demo</title>
  <script>
    function reportEnvironment() {
      const displayMetrics = {
        availableWidth: screen.availWidth,
        availableHeight: screen.availHeight,
        pixelDepth: screen.colorDepth
      };
      
      const clientDetails = {
        userAgentString: navigator.userAgent,
        platformName: navigator.platform,
        languageCode: navigator.language
      };

      console.table(displayMetrics);
      console.table(clientDetails);
    }
  </script>
</head>
<body onload="reportEnvironment()">
</body>
</html>

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.