Solved

different starting page in a website

Posted on 2012-03-15
2
386 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

777 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