Solved

different starting page in a website

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

760 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