Link to home
Start Free TrialLog in
Avatar of alanmcclure
alanmcclure

asked on

javascript clientside cookie to skip flash intro after first viewing

Hello, I came across this statement on the macromedia site under usability issues, I would like to know how to do this.

"While intro animations are exciting, they often delay the user's access to the information they seek. Always offer users either a Skip Intro command or alternative access to your home page. On their second visit to your home page, skip the intro animation altogether (use a client-side JavaScript cookie to accomplish this) then on the destination page give the option of returning to the animation."

Actually, I would prefer a cut and paste problem solver, or a behavior package for dreamweaver 3.  I don't want to go through all the trouble of deciphering the javascript commands and what they do, rather, I would like to concentrate on the flash itself.  The simplest and easiest solution gets the points.

Thanks guys,

Alan
ASKER CERTIFIED SOLUTION
Avatar of RoyKruyshaar
RoyKruyshaar

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
Avatar of alanmcclure
alanmcclure

ASKER

I will take a look at it tomorrow and let you know if I understand it all.  But it looks like it does exactly what I want
Good luck with it

Greetings,

Roy
here's the deal, it works.  However, when I use netscape, the movie takes up the entire screen. Any idea on what to change in the code so that netscape realizes what size window to open.  I see the window sizes above in the code, but with netscape 4.75, it isn't working.
also, if I would like the animation to open and then go to the new page without opening two windows, and then just the second time around, it goes straight to the second page, how would I do this.  I maybe should have been more clear, so I will raise the point amount to 200
Thanks
I just found a site that does something like I want, but it seems to all be happening on the same page all within flash run by javascript.
http://store.infocus.com/
Hi Alan,

I understand what you want.
I check it out within 2 hours. At the moment I'm in a course, so I can't do very much. In my lunchbreak I shall solve it for you.

Greetings,

Roy
Hi Alan,

Here is the solution:

Keep the functions 'getCookie(NameOfCookie)' and 'setCookie(NameOfCookie, value, expiredays)' still between your HEAD-tags.
You can delete the other functions.
Than, somewhere between your BODY-tags (on the place you want your flashMovie) the following script:

  <script language="JavaScript" type="text/javascript">        
    introMovie = getCookie("intromov");
    if (introMovie!="true")    
    {
      document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'")
      document.write(" codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'")
      document.write(" WIDTH=550 HEIGHT=400>")
      document.write(" <PARAM NAME=movie VALUE='introMovie.swf'> <PARAM NAME=quality VALUE=high> <PARAM NAME=scale VALUE=noborder> <PARAM NAME=bgcolor VALUE=#FFFFFF> ")
      document.write(" <EMBED src='introMovie.swf' quality=high scale=noborder bgcolor=#000000 ")
      document.write(" WIDTH=400 HEIGHT=550 TYPE='application/x-shockwave-flash' ")
      document.write(" PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'>")
      document.write(" </EMBED></OBJECT>")
      setCookie('intromov', true, 365)
    }
    else
    {
      document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'")
      document.write(" codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'")
      document.write(" WIDTH=550 HEIGHT=400>")
      document.write(" <PARAM NAME=movie VALUE='mainMovie.swf'> <PARAM NAME=quality VALUE=high> <PARAM NAME=scale VALUE=noborder> <PARAM NAME=bgcolor VALUE=#FFFFFF> ")
      document.write(" <EMBED src='mainMovie.swf' quality=high scale=noborder bgcolor=#000000 ")
      document.write(" WIDTH=550 HEIGHT=400 TYPE='application/x-shockwave-flash' ")
      document.write(" PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'>")
      document.write(" </EMBED></OBJECT>")
     }

  // -->
</script>

The idear is quite te same. On entering the page Javascript looks for a cookie, doesn't it exist he writes the Object code for your intromovie, exists the cookie, he writes the code for your main-flash movie.
The only thing you have to do is in your introMovie, put an action at the and of the movie and as button action that flash loads the main movie.

Well, I hope this will be clear for you. I've tested in ie and NN4.7 and works both ways.

When you have further questions, please feel free to ask.

Greetings,

Roy
         
Be sure that the line which is broken is one line in your script, otherwise you wil get some problems.

Greetings,

Roy
hey, thanks, I'll try it out after a good night of sleep.  One last thing though, if I wanted it to go to a new page instead of just loading a different flash file, in the else section what line of code would I need to put to tell it to automatically go to for example http://www.yahoo.com
In otherwords, here is the code you have with the second part taken out and in parentheses the url, what would the code need to be there?

<script language="JavaScript" type="text/javascript">        
   introMovie = getCookie("intromov");
   if (introMovie!="true")    
   {
     document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'")
     document.write(" codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'")
     document.write(" WIDTH=550 HEIGHT=400>")
     document.write(" <PARAM NAME=movie VALUE='introMovie.swf'> <PARAM NAME=quality VALUE=high> <PARAM
NAME=scale VALUE=noborder> <PARAM NAME=bgcolor VALUE=#FFFFFF> ")
     document.write(" <EMBED src='introMovie.swf' quality=high scale=noborder bgcolor=#000000 ")
     document.write(" WIDTH=400 HEIGHT=550 TYPE='application/x-shockwave-flash' ")
     document.write(" PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'>")
     document.write(" </EMBED></OBJECT>")
     setCookie('intromov', true, 365)
   }
   else
   {
     (http://www.yahoo.com)
}

 // -->
</script>

Again, thanks for your help, I have a feeling that I almost have it.

Alan

hmmm,
this is what I have as you wrote so far:

<html>
<head>


    <script language="JavaScript" type="text/javascript">
    <!--
         function getCookie(NameOfCookie)
         {
              if (document.cookie.length > 0)
              {
                   begin = document.cookie.indexOf(NameOfCookie+"=");
                   if (begin != -1)
                   {
                        begin += NameOfCookie.length+1;
                        end = document.cookie.indexOf(";", begin);
                        if (end == -1) end = document.cookie.length;
                        return unescape(document.cookie.substring(begin, end));
                   }
              }
              return null;
         }

         function setCookie(NameOfCookie, value, expiredays)
         {
              var ExpireDate = new Date ();
              ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
              document.cookie = NameOfCookie + "=" + escape(value)
              + ((expiredays == null) ? "" : "; expires=none" + ExpireDate.toGMTString());
         }


</head>

<body bgcolor="#FFFFFF">

<script language="JavaScript" type="text/javascript">        
   introMovie = getCookie("intromov");
   if (introMovie!="true")    
   {
     document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'")
     document.write(" codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'")
     document.write(" WIDTH=550 HEIGHT=400>")
     document.write(" <PARAM NAME=movie VALUE='images/intro.swf'> <PARAM NAME=quality VALUE=high> <PARAM
NAME=scale VALUE=noborder> <PARAM NAME=bgcolor VALUE=#FFFFFF> ")
     document.write(" <EMBED src='images/intro.swf' quality=high scale=noborder bgcolor=#000000 ")
     document.write(" WIDTH=400 HEIGHT=550 TYPE='application/x-shockwave-flash' ")
     document.write(" PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'>")
     document.write(" </EMBED></OBJECT>")
     setCookie('intromov', true, 365)
   }
   else
   {
     document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'")
     document.write(" codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'")
     document.write(" WIDTH=550 HEIGHT=400>")
     document.write(" <PARAM NAME=movie VALUE='images/main.swf'> <PARAM NAME=quality VALUE=high> <PARAM
NAME=scale VALUE=noborder> <PARAM NAME=bgcolor VALUE=#FFFFFF> ")
     document.write(" <EMBED src='images/main.swf' quality=high scale=noborder bgcolor=#000000 ")
     document.write(" WIDTH=550 HEIGHT=400 TYPE='application/x-shockwave-flash' ")
     document.write(" PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'>")
     document.write(" </EMBED></OBJECT>")
    }
//-->
</script>
hi
</body>
</html>


but it doesn't seem to be working.
Did I mess up somewhere?

Alan
I figured out that I was missing
//-->
</script>

at the end of the javascript in the head tag, and missing
-->
at the beginning of the body tag, but it still isn't working even after I changed all of that.  So, here is the code that I now have:

<html>
<head>


    <script language="JavaScript" type="text/javascript">
    <!--
         function getCookie(NameOfCookie)
         {
              if (document.cookie.length > 0)
              {
                   begin = document.cookie.indexOf(NameOfCookie+"=");
                   if (begin != -1)
                   {
                        begin += NameOfCookie.length+1;
                        end = document.cookie.indexOf(";", begin);
                        if (end == -1) end = document.cookie.length;
                        return unescape(document.cookie.substring(begin, end));
                   }
              }
              return null;
         }

         function setCookie(NameOfCookie, value, expiredays)
         {
              var ExpireDate = new Date ();
              ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
              document.cookie = NameOfCookie + "=" + escape(value)
              + ((expiredays == null) ? "" : "; expires=none" + ExpireDate.toGMTString());
         }

//-->
</script>
</head>

<body bgcolor="#FFFFFF">

<script language="JavaScript" type="text/javascript">  
<!--      
   introMovie = getCookie("intromov");
   if (introMovie!="true")    
   {
     document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'")
     document.write(" codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'")
     document.write(" WIDTH=550 HEIGHT=400>")
     document.write(" <PARAM NAME=movie VALUE='images/intro.swf'> <PARAM NAME=quality VALUE=high> <PARAM
NAME=scale VALUE=noborder> <PARAM NAME=bgcolor VALUE=#FFFFFF> ")
     document.write(" <EMBED src='images/intro.swf' quality=high scale=noborder bgcolor=#000000 ")
     document.write(" WIDTH=400 HEIGHT=550 TYPE='application/x-shockwave-flash' ")
     document.write(" PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'>")
     document.write(" </EMBED></OBJECT>")
     setCookie('intromov', true, 365)
   }
   else
   {
     document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'")
     document.write(" codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'")
     document.write(" WIDTH=550 HEIGHT=400>")
     document.write(" <PARAM NAME=movie VALUE='images/main.swf'> <PARAM NAME=quality VALUE=high> <PARAM
NAME=scale VALUE=noborder> <PARAM NAME=bgcolor VALUE=#FFFFFF> ")
     document.write(" <EMBED src='images/main.swf' quality=high scale=noborder bgcolor=#000000 ")
     document.write(" WIDTH=550 HEIGHT=400 TYPE='application/x-shockwave-flash' ")
     document.write(" PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'>")
     document.write(" </EMBED></OBJECT>")
    }
//-->
</script>
</body>
</html>


Hi Alan,

Just put these this line:

document.write(" <PARAM NAME=movie VALUE='images/intro.swf'> <PARAM NAME=quality VALUE=high> <PARAM

and this line

NAME=scale VALUE=noborder> <PARAM NAME=bgcolor VALUE=#FFFFFF> ")

together with a space between. Now it seems like that they are two separate lines, and then the document.write command will not work.

Your other question about loading another page the second time visit. Put this in the else section:

location.href=("http://www.yahoo.com")

Well, this is it, but when you have further questions, please feel fre to ask

Greetings,

Roy

perfect perfect.  All of my answers were answered exactly.
Thank you very much.

Alan