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
LVL 2
InnerChildAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bubbledragonCommented:
<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>
0
InnerChildAuthor Commented:
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
0
bubbledragonCommented:
<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>
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

InnerChildAuthor Commented:
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
0
bubbledragonCommented:
<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>
0
InnerChildAuthor Commented:
Still getting a error at line 11

oHomePage.setHomePage(location.href);

permission denied

Thanks

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


Thanks

IC
0
bubbledragonCommented:
IE Only.

I test above is work for me.
The setHomePage method I refer to MSDN.

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/behaviors/reference/methods/sethomepage.asp
0
bubbledragonCommented:
If still can't, could you post  your run HTML source.
0
InnerChildAuthor Commented:
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
0
bubbledragonCommented:
OK~

I found the problem will cause on the clever Window XP platform with SP2 ONLY.

It's working for Win2000, Win98.

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/overview/Popup_Blocker.asp

You cannot automatically to setHomepage by onLoad or other method until the user trigger the function by himself.

<BODY onClick="checkCookie()"> try  changed the onLoad to onClick, when user click the page body will prompt the setHomepage function.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
InnerChildAuthor Commented:
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
0
bubbledragonCommented:
don't miss the HTML declare
<HTML XMLNS:IE>
0
InnerChildAuthor Commented:
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
0
InnerChildAuthor Commented:
nm
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.