how to make a page default

delon

Banned
Messages
397
Reaction score
0
Points
0
see i created multiple homepages for website ( eg. multiple homepages with different color ). but when a visitor selects an another color for the homepage, the next time he comes to my website he would see the old homepage not the color he chosed. how can i do this. an example can be seen on aol.com.
 

LHVWB

New Member
Messages
1,308
Reaction score
0
Points
0
If you are just changing some setting within the site, then you can check for the colour by setting a cookie that doesn't have an expiry date. If you could post the code that you are using to swap the colours or at least the language that you are doing it in then that could be useful. ;)
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
An example (JUST AN EXAMPLE, DON'T ACTUALLY USE THIS!)
If you'ld make this "index.php"
PHP:
<?php
if(isset($_GET["color"]) {
setcookie("color", $_GET["color"]);
include $_GET["color"].".php";
exit;
}
if(isset($_COOKIE["color"])) {
if($_COOKIE["color"] == "red") {
include "red.php";
exit;
}
if($_COOKIE["color"] == "blue") {
include "blue.php";
exit;
}
}
include "standard.php";
exit;
?>

You could change the cookie with "index.php?color=color", and the php would include from "red.php", "blue.php" etc...

If you really have no clue about making this, give us really specific info so one of us can make it for you.

Note: DO NOT ACTUALLY USE THIS CODE! It's not safe and probably it doesn't even work like it should.
 
Last edited:

delon

Banned
Messages
397
Reaction score
0
Points
0
see i want a page where it shows boxes with different color filled ( eg. red, blue, green ) in which allow the users to customize the page of their choice.
now i visit the page and click on green a new page is shown where instead of yellow ( the default page ) everything is shown green with same content ( as on the main default one ). but now whenever i visit again the website instead of the yellow page i want to see the green page without changing the color of the page again.
 

sharoncenter9

New Member
Messages
3
Reaction score
0
Points
0
I would agree with the code that marshian put up there a structure as to how to do it. Using a cookie to save the color value which will never expire, and then taking the data from that cookie to set the color of the page. I would use a switch statement to include the different pages from the cookie, but still use the isset for setting the cookie. The logic of it is that when they click the button, the page will be reloaded, but with the different color, but when the page is reloaded the cookie will be set with the new page included, and then when the user returns to the page, the cookie will be loaded, and the switch statement will show the correct page based on what is in the cookie value. In the pages to be included, they can have the same content being dynamically loaded into it, just different css properties for where you want the different colors to be for that page. But marshian's example is a good basic example for starting out on how to do what you want to do.
 

delon

Banned
Messages
397
Reaction score
0
Points
0
thanks crisp, is there anyone who can provide me some tutorials on it in not an professional way.
 

crisp

New Member
Messages
85
Reaction score
0
Points
0
No probs, quick tut...
Create some stylesheets for your site

stylesheet one has your default colour scheme
name this one eg: style.css (or whatever your stylesheet is called currently)
Code:
body {
    background: white;
}

stylesheet two has your first alternate colour
name this eg: blue.css
Code:
body {
    background: blue;
}

stylesheet three, second alternate colour
name this eg: green.css
Code:
body {
    background: green;
}

download the styleswitcher.js javascript file from alistapart, and upload it to your site along with the style sheets

add the links to the head section of your html page

Code:
<head>

<link rel="stylesheet" type="text/css" href="style.css" title="default" />
<link rel="alternate stylesheet"  type="text/css" href="blue.css"  title="blue" />
<link rel="alternate stylesheet"  type="text/css" href="green.css"  title="green" />
<script type="text/javascript" 
src="/styleswitcher.js"></script>
</head>

now you just need to add links into the body of your html for the styles

<a href="#"
onclick="setActiveStyleSheet('default');
return false;">White Background</a>

<a href="#"
onclick="setActiveStyleSheet('blue');
return false;">Blue background</a>

<a href="#"
onclick="setActiveStyleSheet('green');
return false;">Green background</a>

obviously, this is just a basic example of switching styles, you'll prob want to do more than just change the body background, but it gives you a start
 
Last edited:

delon

Banned
Messages
397
Reaction score
0
Points
0
hi thanks crisp, but i now i want is that when the user selects the green one from now on then i want when the user visits my webpage again i would like that he sees the green page again not the default yellow one.
 

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
hi thanks crisp, but i now i want is that when the user selects the green one from now on then i want when the user visits my webpage again i would like that he sees the green page again not the default yellow one.

See my post. You will need to use this script but it works. example http://jagf.net/bigjoe
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
I'ld still suggest using php, since the user can disable javascript...
and it's easyer in php ^^
 

crisp

New Member
Messages
85
Reaction score
0
Points
0
delon, are you saying the styleswitchers working, (ie the page changes colour as expected), but the settings aren't remembered? If so, either the cookies not being set, or being deleted (browser settings/script blockers can affect this). If not, do you have a test/demo page implemented I can look at?

marshian, either way's ok. The user can just as easily disable cookies and neither way will work then. The js uses no server resources (other than serving the css & js in the first place) and the clients browser does the work client side. For something that is a client side cosmetic change, this makes sense to me.
 
Top