Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

CSS Datei durch Link austauschen?

Empfohlene Antworten

Veröffentlicht

Hi, bin hier gerade am rumbasteln, hab auch schon einiges gefunden aber leider nicht wirklich das richtige.

Will eine Website erstellen, die durch den klick auf einen Link die externe Stylesheet datei verändert. die beiden Stylesheets, nennenwir wie style1.css und style2.css sind schon da.

ich will also das wenn man auf den Link geht style1.css durch style2.css ersetzt wird.

"wichtig" ist, das ein weiterer klick auf den selben link (der is ja noch da, nur die farben haben sich verändert in meinem fall) wieder style2.css durch style1.css zurück-ersetzt wird.

das ganze sollte ohne javascript funktionieren, HTML und PHP is aber ok.

hab mich bissl mit dem style-switcher probiert aber kam nich wirklich klar damit.

geht das überhaupt ohne javascript, das der selbe button (link) die css-datei immer hin und hertauscht?

danke schonmal.


<a href="?style=css1">link</a>
[/PHP]

[PHP]
<?php
$defaultCss = "css1";
$css = array_key_exists('style', $_GET) ? $_GET['style'] : $defaultCss;
$css .= ".css";
echo << LINK
<link rel="stylesheet" href="$css" />
LINK;
?>

klar geht das....

dazu wäre es aber schön wenn du sessions verwendest


<?php
session_start();
if ( empty( $_SESSION['sitestyle'])) {
$_SESSION['sitestyle'] = 'style1.css';
}

if ( !empty( $_GET['sitestyle'])) {
$_SESSION['sitestyle'] = $_GET['sitestyle'];
}

function toggleCss() {
return $_SESSION['sitestyle'] == 'style2.css' ? 'style1.css' : 'style2.css';
}

?>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="<?php echo $_SESSION['sitestyle'] ?>">
</head>
<body>
<a href="?sitestyle=<?php echo toggleCss() ?>">SiteStyle-Wechseln</a>
</body>
</html>
[/PHP]

Hi!

Die "Best-Practice" Lösung hierfür wurde mal sehr gut bei Alistapart beschrieben: http://www.alistapart.com/articles/alternate/

Gruß, Tobias

danke schonmal. mit den sessions gibt es allerdings fehlermeldungen:

Warning: Cannot send session cookie - headers already sent by (output started at /home/httpd/htdocs/***.de/***/index.php:1) in /home/httpd/htdocs/***.de/***/index.php on line 2

Warning: Cannot send session cache limiter - headers already sent (output started at /home/httpd/htdocs/***.de/***/index.php:1) in /home/httpd/htdocs/***.de/***/index.php on line 2

kann damit jemand was anfangen? headers already sent. weiß nicht wieso.

"line2" ist übrigens die, wo die session starten soll.

notfalls dein script bis zum session start posten...

Gruß,

Markus

da ist nichts davor. darum wundere ich mich ja über die Meldung:

<?php

session_start();

if ( empty( $_SESSION['sitestyle'])) {

$_SESSION['sitestyle'] = 'global1.css';

}

if ( !empty( $_GET['sitestyle'])) {

$_SESSION['sitestyle'] = $_GET['sitestyle'];

}

function toggleCss() {

return $_SESSION['sitestyle'] == 'global2.css' ? 'global1.css' : 'global2.css';

}

?>

<html>

<head>

<title>blabla</title>

so gehts in der ersten zeile los.

es geht, hatte mich wohl nur vertippt vorhin. danke nochmal euch allen.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.