Jump to content

Recommended Posts

Here is a link to the demo: [a href=\"http://designx.biz/index.php\" target=\"_blank\"]http://designx.biz/index.php[/a]

If you open the above link in Firefox, you can change the font and background color.

If you open the above link in Internet Explorer, you cannot change the font and background color.

[b]This is driving me nuts, can anyone help me?[/b]

Here is a link to a ZIP file containing all the file: [a href=\"http://designx.biz/styleswitcher.zip\" target=\"_blank\"]http://designx.biz/styleswitcher.zip[/a]

Here is the code for index.php

[code]
<?php
include_once('switcher_background.php');
include_once('switcher_font.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Style Switcher</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" href="css/screen.css">
        <?php include_background(); ?>
        <?php include_font(); ?>
    </head>
    <body>
        <h1>Style Switcher</h1>
        <?php font_style_form_open(); ?>
                <?php font_style_form_list(5); ?>
                <?php font_style_form_button('Switch Font'); ?>
        <?php font_style_form_close(); ?>
        <?php background_style_form_open(); ?>
                <?php background_style_form_list(5); ?>
                <?php background_style_form_button('Switch Background'); ?>
        <?php background_style_form_close(); ?>
    </body>
</html>
[/code]

Here is the code for switcher_background.php

[code]
<?php

$root = $_SERVER['DOCUMENT_ROOT'] . '/';

$background_style_directory = 'css/background/';

$extension = '.css';

$special_character = '_';

function include_background()
{
    global $host, $background_style_directory, $background_style_current, $linebreak;
    
    echo '<link rel="alternative stylesheet" type="text/css" href="' . $background_style_directory . $background_style_current . '" title="User Defined Style" />' . $linebreak;
}

function background_cookie_read()
{
    global $background_styles;
    
    if (isset($_COOKIE['switcher_background']))
    {
        return $_COOKIE['switcher_background'];
    }
    else if (count($background_styles) > 0)
    {
        return $background_styles[0];
    }
    else
    {
        return null;
    }
}

function background_cookie_write($style)
{
    global $host;
    
    if ($host == 'localhost')
    {
        setcookie('switcher_background', $style, time() + 31536000, '/');
    }
    else
    {
        setcookie('switcher_background', $style, time() + 31536000, '/', '.' . $host, '0');
    }
}

function background_style_redirect()
{
    global $host;
    
    if (!empty($_SERVER['HTTP_REFERER']))
    {
        header("Location: " . $_SERVER['HTTP_REFERER']);
    }
    else
    {
        header("Location: http://" . $host);
    }
}

function background_style_files()
{
    global $background_style_directory, $extension;
    $background_styles = array();
    $i = 0;
    
    if (is_dir($root . $background_style_directory))
    {
        if ($handle = opendir($root . $background_style_directory))
        {
            while (false !== ($file = readdir($handle)))
            {
                if (strlen($file) > strlen($extension) && substr($file, strlen($file) - strlen($extension)) == $extension)
                {
                    $background_styles[$i++] = $file;
                }
            }
            
            closedir($handle);
        }
    }
    
    if (count($background_styles) == 0)
    {
        $background_styles[0] = "No Stylesheets Found";
    }
    else
    {
        sort($background_styles);
    }
    
    return $background_styles;
}

function background_style_convert_file_to_title($file)
{
    global $extension, $special_character;
    
    $title = ucfirst(trim(basename($file, $extension)));
    $offset = 0;

    while (true)
    {
        $offset = strpos($title, $special_character, $offset);

        if ($offset === false)
        {
            break;
        }
        else
        {
            if (strlen($title) > ++$offset)
            {
                if ($special_character != ' ')
                {
                    $title = substr($title, 0, $offset - 1) . ' ' . ucfirst(substr($title, $offset, strlen($title)));
                }
                else
                {
                    $title = substr($title, 0, $offset) . ucfirst(substr($title, $offset, strlen($title)));
                }
            }
        }
    }
    
    return $title;
}

function background_style_tabs($amount)
{
    global $tab;
    
    for ($i = 0; $i < $amount; $i++)
    {
        echo $tab;
    }
}

function background_style_form_open()
{
    global $linebreak;
    
    echo '<form action="switcher_background.php" method="post">' . $linebreak;
}

function background_style_form_list($tabs)
{
    global $background_styles, $background_style_current, $linebreak;
    
    echo '<select name="style">' . $linebreak;
    
    for ($i = 0; $i < count($background_styles); $i++)
    {
        background_style_tabs($tabs + 1);
        echo '<option value="' . $background_styles[$i] . '"';
        if ($background_style_current == $background_styles[$i])
        {
            echo ' selected="selected"';
        }
        echo '>' . background_style_convert_file_to_title($background_styles[$i]) . '</option>' . $linebreak;
    }
    
    background_style_tabs($tabs);
    echo '</select>' . $linebreak;
}

function background_style_form_button($label)
{
    echo '<input type="submit" value="';
    echo empty($label) ? "Change" : $label;
    echo '" />';
}

function background_style_form_close()
{
    echo '</form>';
}

$selection     = $_SERVER['QUERY_STRING'];
$ip            = $_SERVER['REMOTE_ADDR'];
$linebreak     = "\r\n";
$tab           = "\t";

$background_styles = background_style_files();

$background_style_current = background_cookie_read();

$host          = (substr($_SERVER['HTTP_HOST'], 0, 4) == 'www.') ? substr($_SERVER['HTTP_HOST'], 4, strlen($_SERVER['HTTP_HOST'])) : $_SERVER['HTTP_HOST'];

if (basename($_SERVER['PHP_SELF']) == 'switcher_background.php')
{
    if ($_POST['style'] != null)
    {
        for ($i = 0; $i < count($background_styles); $i++)
        {
            if ($_POST['style'] == $background_styles[$i])
            {
                background_cookie_write($_POST['style']);
            }
        }
    }
    background_style_redirect();
}

?>
[/code]

Here is the code for switcher_font.php

[code]
<?php

$root = $_SERVER['DOCUMENT_ROOT'] . '/';

$font_style_directory = 'css/font/';

$extension = '.css';

$special_character = '_';

function include_font()
{
    global $host, $font_style_directory, $font_style_current, $linebreak;
    
    echo '<link rel="alternative stylesheet" type="text/css" href="' . $font_style_directory . $font_style_current . '" title="User Defined Style" />' . $linebreak;
}

function font_cookie_read()
{
    global $font_styles;
    
    if (isset($_COOKIE['switcher_font']))
    {
        return $_COOKIE['switcher_font'];
    }
    else if (count($font_styles) > 0)
    {
        return $font_styles[0];
    }
    else
    {
        return null;
    }
}

function font_cookie_write($style)
{
    global $host;
    
    if ($host == 'localhost')
    {
        setcookie('switcher_font', $style, time() + 31536000, '/');
    }
    else
    {
        setcookie('switcher_font', $style, time() + 31536000, '/', '.' . $host, '0');
    }
}

function font_style_redirect()
{
    global $host;
    
    if (!empty($_SERVER['HTTP_REFERER']))
    {
        header("Location: " . $_SERVER['HTTP_REFERER']);
    }
    else
    {
        header("Location: http://" . $host);
    }
}

function font_style_files()
{
    global $font_style_directory, $extension;
    $font_styles = array();
    $i = 0;
    
    if (is_dir($root . $font_style_directory))
    {
        if ($handle = opendir($root . $font_style_directory))
        {
            while (false !== ($file = readdir($handle)))
            {
                if (strlen($file) > strlen($extension) && substr($file, strlen($file) - strlen($extension)) == $extension)
                {
                    $font_styles[$i++] = $file;
                }
            }
            
            closedir($handle);
        }
    }
    
    if (count($font_styles) == 0)
    {
        $font_styles[0] = "No Stylesheets Found";
    }
    else
    {
        sort($font_styles);
    }
    
    return $font_styles;
}

function font_style_convert_file_to_title($file)
{
    global $extension, $special_character;
    
    $title = ucfirst(trim(basename($file, $extension)));
    $offset = 0;

    while (true)
    {
        $offset = strpos($title, $special_character, $offset);

        if ($offset === false)
        {
            break;
        }
        else
        {
            if (strlen($title) > ++$offset)
            {
                if ($special_character != ' ')
                {
                    $title = substr($title, 0, $offset - 1) . ' ' . ucfirst(substr($title, $offset, strlen($title)));
                }
                else
                {
                    $title = substr($title, 0, $offset) . ucfirst(substr($title, $offset, strlen($title)));
                }
            }
        }
    }
    
    return $title;
}

function font_style_tabs($amount)
{
    global $tab;
    
    for ($i = 0; $i < $amount; $i++)
    {
        echo $tab;
    }
}

function font_style_form_open()
{
    global $linebreak;
    
    echo '<form action="switcher_font.php" method="post">' . $linebreak;
}

function font_style_form_list($tabs)
{
    global $font_styles, $font_style_current, $linebreak;
    
    echo '<select name="style">' . $linebreak;
    
    for ($i = 0; $i < count($font_styles); $i++)
    {
        font_style_tabs($tabs + 1);
        echo '<option value="' . $font_styles[$i] . '"';
        if ($font_style_current == $font_styles[$i])
        {
            echo ' selected="selected"';
        }
        echo '>' . font_style_convert_file_to_title($font_styles[$i]) . '</option>' . $linebreak;
    }
    
    font_style_tabs($tabs);
    echo '</select>' . $linebreak;
}

function font_style_form_button($label)
{
    echo '<input type="submit" value="';
    echo empty($label) ? "Change" : $label;
    echo '" />';
}

function font_style_form_close()
{
    echo '</form>';
}

$selection     = $_SERVER['QUERY_STRING'];
$ip            = $_SERVER['REMOTE_ADDR'];
$linebreak     = "\r\n";
$tab           = "\t";

$font_styles   = font_style_files();

$font_style_current = font_cookie_read();

$host          = (substr($_SERVER['HTTP_HOST'], 0, 4) == 'www.') ? substr($_SERVER['HTTP_HOST'], 4, strlen($_SERVER['HTTP_HOST'])) : $_SERVER['HTTP_HOST'];

if (basename($_SERVER['PHP_SELF']) == 'switcher_font.php')
{
    if ($_POST['style'] != null)
    {
        for ($i = 0; $i < count($font_styles); $i++)
        {
            if ($_POST['style'] == $font_styles[$i])
            {
                font_cookie_write($_POST['style']);
            }
        }
    }
    font_style_redirect();
}

?>
[/code]
[!--quoteo(post=377932:date=May 28 2006, 08:07 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ May 28 2006, 08:07 PM) [snapback]377932[/snapback][/div][div class=\'quotemain\'][!--quotec--]I think it's because you are using aleternative style sheets to set the font/color. So probably IE keeps using the main CSS.[/quote]You are right on the money. I changed rel="alternate stylesheet" to rel="stylesheet" and now it works perfectly in IE and Firefox. Thanks!
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.