[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

JavaScript "Set Homepage" cookie

Posted on 2006-03-29
16
Medium Priority
?
1,455 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:InnerChild
  • 8
  • 8
16 Comments
 
LVL 7

Expert Comment

by:bubbledragon
ID: 16328993
<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
 
LVL 2

Author Comment

by:InnerChild
ID: 16329912
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
 
LVL 7

Expert Comment

by:bubbledragon
ID: 16330320
<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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Author Comment

by:InnerChild
ID: 16332238
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
 
LVL 7

Expert Comment

by:bubbledragon
ID: 16333358
<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
 
LVL 2

Author Comment

by:InnerChild
ID: 16333437
Still getting a error at line 11

oHomePage.setHomePage(location.href);

permission denied

Thanks

IC
0
 
LVL 7

Expert Comment

by:bubbledragon
ID: 16334294
Is Frameset ? Are you try to run the above code individual ?
0
 
LVL 2

Author Comment

by:InnerChild
ID: 16334409
Not in a frame just a static page.


Thanks

IC
0
 
LVL 7

Expert Comment

by:bubbledragon
ID: 16334604
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
 
LVL 7

Expert Comment

by:bubbledragon
ID: 16334626
If still can't, could you post  your run HTML source.
0
 
LVL 2

Author Comment

by:InnerChild
ID: 16338138
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
 
LVL 7

Accepted Solution

by:
bubbledragon earned 200 total points
ID: 16339039
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
 
LVL 2

Author Comment

by:InnerChild
ID: 16366333
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
 
LVL 7

Expert Comment

by:bubbledragon
ID: 16366701
don't miss the HTML declare
<HTML XMLNS:IE>
0
 
LVL 2

Author Comment

by:InnerChild
ID: 16377398
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
 
LVL 2

Author Comment

by:InnerChild
ID: 16381118
nm
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…
Suggested Courses

825 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