Widget:GOV-Test: Unterschied zwischen den Versionen
Aus Altes Köln
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 10: | Zeile 10: | ||
const serverBaseURL = "https://gov.genealogy.net"; | const serverBaseURL = "https://gov.genealogy.net"; | ||
fetch('https:// | fetch('https://example.com/fragment') | ||
.then(response => response.text()) | .then(response => { | ||
if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`); | |||
return response.text(); | |||
}) | |||
.then(html => { | .then(html => { | ||
const tempDiv = document.createElement('div'); | const tempDiv = document.createElement('div'); | ||
tempDiv.innerHTML = html; | tempDiv.innerHTML = html; | ||
// | // Links anpassen | ||
const links = tempDiv.querySelectorAll('a[href^="/"]'); | const links = tempDiv.querySelectorAll('a[href^="/"]'); | ||
links.forEach(link => { | links.forEach(link => { | ||
link.href = serverBaseURL + link.getAttribute('href'); | link.href = serverBaseURL + link.getAttribute('href'); | ||
}); | }); | ||
// | // Bilder anpassen | ||
const images = tempDiv.querySelectorAll('img[src^="/"]'); | const images = tempDiv.querySelectorAll('img[src^="/"]'); | ||
images.forEach(img => { | images.forEach(img => { | ||
img.src = serverBaseURL + img.getAttribute('src'); | img.src = serverBaseURL + img.getAttribute('src'); | ||
Zeile 33: | Zeile 35: | ||
contentDiv.innerHTML = tempDiv.innerHTML; | contentDiv.innerHTML = tempDiv.innerHTML; | ||
// Beispiel | // Beispiel-Styling nur für Tabellen innerhalb des Widgets | ||
const tables = contentDiv.querySelectorAll('table'); | const tables = contentDiv.querySelectorAll('table'); | ||
tables.forEach(table => { | tables.forEach(table => { | ||
Zeile 40: | Zeile 42: | ||
}); | }); | ||
}) | }) | ||
.catch(error => console.error(' | .catch(error => console.error('Fehler beim Laden:', error)); | ||
})(); | })(); | ||
</script> | </script> | ||
<style> | <style> | ||
/* Styling für den Widget-Container */ | /* Styling für den isolierten Widget-Container */ | ||
#widget-container { | #widget-container { | ||
margin: 20px auto; | margin: 20px auto; /* Zentrierung und Abstand */ | ||
padding: 10px; | padding: 10px; /* Innenabstand */ | ||
border: 1px solid #ccc; | border: 1px solid #ccc; /* Rahmen für Sichtbarkeit */ | ||
background-color: #f9f9f9; | background-color: #f9f9f9; /* Hintergrundfarbe */ | ||
overflow: auto; /* Verhindert, dass | overflow: auto; /* Verhindert, dass der Inhalt über den Container hinausfließt */ | ||
} | } | ||
/* CSS wirkt sich nur auf Tabellen innerhalb des Widgets aus */ | |||
#widget-container table { | #widget-container table { | ||
border-collapse: collapse; | border-collapse: collapse; | ||
Zeile 62: | Zeile 65: | ||
border: 1px solid #ddd; | border: 1px solid #ddd; | ||
padding: 8px; | padding: 8px; | ||
} | |||
#widget-container th { | |||
text-align: left; | |||
background-color: #f2f2f2; | |||
} | } | ||
</style> | </style> |
Version vom 21. Januar 2025, 13:43 Uhr
Ajax-Variante mit wiki
<script>
(function() { // Festgelegter Servername const serverBaseURL = "https://gov.genealogy.net";
fetch('https://example.com/fragment') .then(response => { if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`); return response.text(); }) .then(html => { const tempDiv = document.createElement('div'); tempDiv.innerHTML = html;
// Links anpassen const links = tempDiv.querySelectorAll('a[href^="/"]'); links.forEach(link => { link.href = serverBaseURL + link.getAttribute('href'); });
// Bilder anpassen const images = tempDiv.querySelectorAll('img[src^="/"]'); images.forEach(img => { img.src = serverBaseURL + img.getAttribute('src'); });
// Manipulierten Inhalt in den Widget-Container einfügen const contentDiv = document.getElementById('content'); contentDiv.innerHTML = tempDiv.innerHTML;
// Beispiel-Styling nur für Tabellen innerhalb des Widgets const tables = contentDiv.querySelectorAll('table'); tables.forEach(table => { table.style.width = '100%'; table.style.fontFamily = 'Arial, sans-serif'; }); }) .catch(error => console.error('Fehler beim Laden:', error)); })();
</script>
<style>
/* Styling für den isolierten Widget-Container */ #widget-container { margin: 20px auto; /* Zentrierung und Abstand */ padding: 10px; /* Innenabstand */ border: 1px solid #ccc; /* Rahmen für Sichtbarkeit */ background-color: #f9f9f9; /* Hintergrundfarbe */ overflow: auto; /* Verhindert, dass der Inhalt über den Container hinausfließt */ }
/* CSS wirkt sich nur auf Tabellen innerhalb des Widgets aus */ #widget-container table { border-collapse: collapse; width: 100%; }
#widget-container td, #widget-container th { border: 1px solid #ddd; padding: 8px; }
#widget-container th { text-align: left; background-color: #f2f2f2; }
</style>
Variante: Einfacher iframe mit
Variante: responsiv mit
<style>
body { margin: 0; padding: 0; font-family: Arial, sans-serif; }
.iframe-container { width: 100%; /* Container hat immer die volle Breite des Viewports */ position: relative; /* Wichtig für absolute Positionierung */ padding-top: 56.25%; /* Seitenverhältnis 16:9 */ }
iframe { position: absolute; top: 0; left: 0; width: 100vw; /* Breite des Viewports */ height: calc(100vw * 0.5625); /* Höhe proportional zur Breite (16:9) */ transform-origin: top left; /* Skalierung startet oben links */ }
/* Media Queries für kleinere Bildschirme */ @media (max-width: 768px) { iframe { transform: scale(0.9); /* Skaliere den iframe-Inhalt */ } }
@media (max-width: 480px) { iframe { transform: scale(0.8); /* Weitere Skalierung für kleine Geräte */ } } </style>