Link to home
Start Free TrialLog in
Avatar of InnerChild
InnerChild

asked on

JavaScript "Set Homepage" cookie

So really what I am looking for is a script that will ask the person to set the page they are at as their homepage.  If they say yes it will remember them and never ask again.  If no it will allow them to go about their business but the next time they come back it will ask again.

I think this is easy for most....just not me.

Thanks

IC
Avatar of bubbledragon
bubbledragon

<html>
<body onLoad="checkCookie()">
<script>
function setCookie() {
 now=new Date()
 now.setTime( now.getTime() + 1000 * 60 * 60 * 24 * 365)
 document.cookie="visited=true; expires=" + now.toGMTString()
}

function checkCookie() {
  if (!document.cookie)
    if (confirm("Remember you. OK?"))
       setCookie();
}
</script>
</body>
</html>
Avatar of InnerChild

ASKER

It didn;t work the way I need it to but it is close.  I need it to set it as the homepage as well.

Step by step

Person goes to homepage and is asked if they want to set that page as their homepage
if yes
then homepage is set to current homepage
if no
person can continue to browse website and if they come back they are asked again to set the page as their homepage.

Right now the window asks to remember but the homepage doesn't change.

Thanks

IC
<HTML>
<body onLoad="checkCookie()">
<script>
function setCookie() {
  now=new Date()
  now.setTime( now.getTime() + 1000 * 60 * 60 * 24 * 365)
  document.cookie="visited=true; expires=" + now.toGMTString()
}

function checkCookie() {
  if (!document.cookie)
      if (confirm("Don't forgot me. OK?")) {
      document.body.style.behavior='url(#default#homepage)';
      document.body.setHomePage(location.href);
      event.returnValue = false;
        setCookie();
  }
}
</script>
</body>
</html>
Still not working I am getting a permissions error.  I was doing some reading and I know you can't force the change and thet the user will need to accept it.  Can the javascript just get that box to open asking the person if they want the homepage changed?  As well as remember them?

Thanks

IC
<HTML XMLNS:IE>
<HEAD>
<STYLE>
@media all {
   IE\:homePage {behavior:url(#default#homepage)}
}  
</STYLE>

<SCRIPT>
function fnSet(){
      oHomePage.setHomePage(location.href);
      event.returnValue = false;
}
function setCookie() {
      now=new Date()
      now.setTime( now.getTime() + 1000 * 60 * 60 * 24 * 365)
      document.cookie="visited=true; expires=" + now.toGMTString()
}

function checkCookie() {
      if (!document.cookie) {
            fnSet();
            sQueryHome = oHomePage.isHomePage(location.href);
            if (sQueryHome) setCookie();
            event.returnValue = false;
      }
}
</SCRIPT>
</HEAD>
<BODY onLoad="checkCookie()">
<IE:homePage ID="oHomePage" />
</BODY>
</HTML>
Still getting a error at line 11

oHomePage.setHomePage(location.href);

permission denied

Thanks

IC
Is Frameset ? Are you try to run the above code individual ?
Not in a frame just a static page.


Thanks

IC
If still can't, could you post  your run HTML source.
All I did was a cut and paste from what you had.

<HTML XMLNS:IE>
<HEAD>
<STYLE>
@media all {
   IE\:homePage {behavior:url(#default#homepage)}
}  
</STYLE>

<SCRIPT>
function fnSet(){
     oHomePage.setHomePage(location.href);
     event.returnValue = false;
}
function setCookie() {
     now=new Date()
     now.setTime( now.getTime() + 1000 * 60 * 60 * 24 * 365)
     document.cookie="visited=true; expires=" + now.toGMTString()
}

function checkCookie() {
     if (!document.cookie) {
          fnSet();
          sQueryHome = oHomePage.isHomePage(location.href);
          if (sQueryHome) setCookie();
          event.returnValue = false;
     }
}
</SCRIPT>
</HEAD>
<BODY onLoad="checkCookie()">
<IE:homePage ID="oHomePage" />
</BODY>
</HTML>

Still getting a permissions error on 3 different machines.

Thanks

IC
ASKER CERTIFIED SOLUTION
Avatar of bubbledragon
bubbledragon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just when you thought I was gone.  The script works great in a static stie but I tried to use it in a ASP application where a header file has the <head> and <body> tags but nothing happens, not even a error.  If you have any thoughts I would appricicate them.

Thanks

IC
don't miss the HTML declare
<HTML XMLNS:IE>
It already has a wierd declare in the head tag '<head xmlns:eba>'

I think the way you did it was slick but I would rather have simple and working in the application, so do you have a simple popup version where when they get to the page the get a popup and when they click the link they are asked to bookmark the website and if they do then it never pops open again but if they don't then it will popup everytime they go there.  If you can get this done I'll find a way of getting you more points.

Thanks

IC
nm