0Pricing
Browser Extensions Development (Chrome & Edge) · Lektion

Interaktive Popup-Oberflächen erstellen

Entwickeln Sie dynamische und responsive Popup-Oberflächen mit HTML, CSS und JavaScript, um schnelle Benutzerinteraktionen zu ermöglichen.

Interaktive Popup-Oberflächen erstellen ist eine kostenlose Browser Extensions Development (Chrome & Edge)-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Browser Extensions Development (Chrome & Edge)-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Browser Extensions Development (Chrome & Edge)-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

What are Extension Popups?

Browser extensions often need a small user interface to interact with. This is where popup pages come in!

  • A popup is a small window that appears when you click your extension's icon in the browser toolbar.
  • It's perfect for quick actions, displaying information, or simple settings.
  • Popups are temporary: they close automatically when you click outside them or switch tabs.

Declaring Your Popup UI

To tell your browser extension which HTML file to use as its popup, you specify it in your manifest.json file.

You use the "action" key, and then "default_popup" points to your HTML file.

{
  "manifest_version": 3,
  "name": "My Popup Extension",
  "version": "1.0",
  "action": {
    "default_popup": "popup.html",
    "default_icon": "icon.png"
  }
}

Popup's HTML Structure

Your popup is essentially a miniature web page. It uses standard HTML to define its structure and content.

Create a file named popup.html (or whatever you set in manifest.json) and add your HTML.

<!DOCTYPE html>
<html>
<head>
  <title>My Popup</title>
</head>
<body>
  <h1>Hello from Popup!</h1>
  <p>This is your extension's user interface.</p>
</body>
</html>

Styling Your Popup with CSS

Just like any web page, you can use CSS to style your popup. Link a CSS file in your popup.html's <head> section.

Keep popup styles concise for a small, focused UI.

/* popup.css */
body {
  font-family: sans-serif;
  width: 200px; /* Keep popups small */
  padding: 10px;
  background-color: #f0f0f0;
}
h1 {
  color: #333;
  font-size: 1.2em;
}

Adding Interactivity with JavaScript

To make your popup dynamic and responsive, you'll need JavaScript. Link your script file in your popup.html, usually before the closing </body> tag.

This script runs every time the popup is opened.

// popup.js
document.addEventListener('DOMContentLoaded', () => {
  console.log('Popup script loaded!');
  // Your interactive code goes here
});

Understanding Popup Script Execution

When a user clicks your extension icon, the browser loads and executes your popup.html and its linked JavaScript.

  • Each time the popup opens, the script runs from scratch.
  • It has access to standard web APIs (DOM, fetch) and specific browser extension APIs (chrome.*).
  • When the popup closes, its JavaScript context is destroyed.

Example: Simple Click Counter

Let's create a basic popup that counts how many times a button is clicked.

For this to work, your popup.html needs a <span id="count"> and a <button id="increment">.

// popup.js
let count = 0;
document.addEventListener('DOMContentLoaded', () => {
  const countDisplay = document.getElementById('count');
  const incrementButton = document.getElementById('increment');

  countDisplay.textContent = count;

  incrementButton.addEventListener('click', () => {
    count++;
    countDisplay.textContent = count;
  });
});

Accessing Browser Extension APIs

Popup scripts can directly use many chrome.* APIs to interact with the browser, tabs, and extension itself.

For example, you can get information about your extension using chrome.runtime.getManifest().

// popup.js
document.addEventListener('DOMContentLoaded', () => {
  const manifest = chrome.runtime.getManifest();
  const versionElement = document.getElementById('version');
  if (versionElement) {
    versionElement.textContent = `v${manifest.version}`;
  }
  console.log('Extension Name:', manifest.name);
});

Popup Best Practices

Since popups are temporary, it's crucial to keep them lightweight and performant.

  • Keep it small: A popup should have a clear, single purpose.
  • Fast loading: Avoid heavy images or complex computations.
  • Responsive design: Ensure it looks good on various screen sizes.
  • Minimize network requests: Fetch data efficiently or pre-fetch in the background script if possible.

Popup Knowledge Check

Let's test your understanding of extension popups.

Recap: Interactive Popups

Great job! You've learned the fundamentals of creating interactive popup UIs for your browser extensions.

  • Popups are small, temporary UIs linked in manifest.json via "action".
  • They use standard HTML, CSS, and JavaScript.
  • Popup scripts run when the popup opens and are destroyed when it closes.
  • They can access browser extension APIs for dynamic interactions.

Next, you'll explore how to build more persistent configuration UIs with Options Pages!

Häufig gestellte Fragen

Ist die Lektion „Interaktive Popup-Oberflächen erstellen“ kostenlos?

Ja — der vollständige Text von „Interaktive Popup-Oberflächen erstellen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Browser Extensions Development (Chrome & Edge)-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Browser Extensions Development (Chrome & Edge)-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Interaktive Popup-Oberflächen erstellen“?

Entwickeln Sie dynamische und responsive Popup-Oberflächen mit HTML, CSS und JavaScript, um schnelle Benutzerinteraktionen zu ermöglichen. Du übst Browser Extensions Development (Chrome & Edge) mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Browser Extensions Development (Chrome & Edge) zu starten?

Keine Vorkenntnisse erforderlich. Browser Extensions Development (Chrome & Edge) auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.

Wie lange dauert die Lektion „Interaktive Popup-Oberflächen erstellen“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Browser Extensions Development (Chrome & Edge)-Lektion Code schreiben und ausführen?

Ja. Jede Browser Extensions Development (Chrome & Edge)-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Interaktive Popup-Oberflächen erstellen
  2. Eine Optionsseite erstellen
  3. Kommunikation zwischen UI-Komponenten
  4. Theming mit CSS und Unterstützung für den Dark Mode
← Zurück zu Browser Extensions Development (Chrome & Edge)