Solved

different starting page in a website

Posted on 2012-03-15
2
384 Views
Last Modified: 2013-11-19
Hi,

How can I have users make a page the start page within a website. For example, we have a several tabs (category A, category B, ...). One user wants their start page A the other B when they visit our website. I want to put a button or link saying "Make this page my starging page". Once they click that link, whenever they visit our website, category B will be the first page they see. I understand if they clear cache, it will be gone.

Thank you.
0
Comment
Question by:Naratech
2 Comments
 
LVL 7

Accepted Solution

by:
micropc1 earned 500 total points
ID: 37727597
If the page uses some kind of logon framework I would store the information in their user profile, then load the page the next time they log on, but since this question is under Javascript/Web Dev I'm assuming you are looking for a Javascript solution...

You could use cookies and redirect them based on their saved selection. Using the example code from W3Schools (http://www.w3schools.com/js/js_cookies.asp) you could do something like...

var setCookie = function (c_name,value,exdays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
};

var getCookie = function (c_name) {
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
};

var startPage=getCookie("startPage");

//if a start page cookie is set, redirect the user
if (startPage!=null && startPage!="") {
	location.href = startPage;

//otherwise go to the default page
} else {
	location.href = "defaultPage.html";
}

Open in new window


and to set the cookie you would do...

setCookie("startPage",startPage,365);

Open in new window

0
 

Author Closing Comment

by:Naratech
ID: 37727713
Thank you. I think I can make this work on my website.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now