PDA

View Full Version : cookie redirecting from dhtml page



its_jon
Nov 19th, 2005, 07:30 PM
I have set up a dhtml splash screen {AFTER} creating a large website.

This means that all my internal links to the 'homepage' which is index.htm now show the user the splash screen every single time they want the homepage.

index.htm (splashscreen) redirects to index2.htm (the homepage)

Rarther than update every single index.htm link to index2.htm is there a way for index.htm to redirect to index2.htm before the splashscreen code is executed by detecting if that page has already been visited.

??????????

I am told two ways exist ,,, one with javascriopt/cookies and the other by php. Either way I am very novice at html....I cut and paste everything with some help from notetab light.


any help most appreciated...... site in question is here. http://jedforestinstrumentalband.org.uk

pccode
Nov 20th, 2005, 05:51 AM
Your best bet is using cookies. Just insert the code below into your index.htm page.



if (document.cookie) {
window.location.href="http://jedforestinstrumentalband.org.uk/index2.htm";
} else {
expires = new Date();
expires.setTime(expires.getTime() + 24 * 60 * 60 * 1000);
document.cookie = "name=value; expires=" + expires.toGMTString();
}


The cookie will be set to expire in 24 hours. You can change how many days the cookie remains set with the code below:



// remains set for 2 days
expires.getTime() + 24 * 60 * 60 * 2 * 1000

// remains set for 1 week
expires.getTime() + 24 * 60 * 60 * 7 * 1000

// remains set for 1 year
expires.getTime() + 24 * 60 * 60 * 365 * 1000


You can change the cookie's path by adding "path=" to the document.cookie object.



// path=/ makes the cookie available to the entire domain
document.cookie = "name=value; expires=" + expires.toGMTString() + "; path=/";