#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    4
    Rep Power
    0

    Question Javascript: plugin detect and cookie redirect scripts conflicting???


    I'm VERY new to jscript - I have a question on a page I'm doing.

    I want it to do 2 things:
    1. Detect if Flash is installed, and send to appropriate page if yes or no.
    2. Regardless of above, send user to a certain page after 2 visits, thus skipping the flash intro.

    I have correct code to do both of these tasks, but are they playing well together on the page???? Is one superceding the other????

    Here's code, any help is appreciated (sorry for posting all the code, but I didn't think I could leave any out):

    Code:
    <head>
    
    <script language="JavaScript" type="text/JavaScript">
    <!-- this script detects if Flash is installed:
    function MM_checkPlugin(plgIn, theURL, altURL, autoGo) { //v4.0
      var ok=false; document.MM_returnValue = false;
      with (navigator) if (appName.indexOf('Microsoft')==-1 || (plugins && plugins.length)) {
        ok=(plugins && plugins[plgIn]);
      } else if (appVersion.indexOf('3.1')==-1) { //not Netscape or Win3.1
        if (plgIn.indexOf("Flash")!=-1 && window.MM_flash!=null) ok=window.MM_flash;
        else if (plgIn.indexOf("Director")!=-1 && window.MM_dir!=null) ok=window.MM_dir;
        else ok=autoGo; }
      if (!ok) theURL=altURL; if (theURL) window.location=theURL;
    }
    //-->
    </script>
    <script language="JavaScript"><!--
    function getCookieVal(offset)
    {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
    }
    
    function GetCookie(name)
    {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
    {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return getCookieVal(j);
    
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0)
    break;
    }
    return "";
    }
    // --></script>
    
    <script
    language="JavaScript">  <!--
    //sends user to different page after 2 visits
    
    expDays = 30;
    exp = new Date();
    exp.setTime(exp.getTime() + (expDays * 24 * 60 * 60 * 1000));
    
    function SetCookie(name, value)
    {
    document.cookie = name + "=" + escape(value) + "; expires=" + exp.toGMTString();
    }
    
    var ny = GetCookie("ny")
    
    if (ny!="1" || ny!="2" || ny!="ok"){
    SetCookie("ny", "1");
    }
    
    if (ny=="1"){
    SetCookie("ny", "2");
    }
    
    if (ny=="2" || ny=="ok"){
    SetCookie("ny", "ok");
    }
    // --></script>
    
    <script language="JavaScript"><!--
    var ny = GetCookie("ny")
    
    if (ny=="1" || ny=="2" ){
    // Where do you want the user to go the first two times 
    //he visits your site?
    window.location = "intro.htm";
    }
    
    if (ny=="ok"){
    // Where do you want the user to go the afterwards?
    window.location = "index2.htm";
    }
    // --></script>
    </head>
    
    <body onLoad="MM_checkPlugin('Shockwave Flash','intro.htm','index2.htm',true);return document.MM_returnValue">
    <div align="center"><font size="1" face="Arial, Helvetica, sans-serif">detecting</font></div>
    </body>
    </html>
    Last edited by agostumpy; July 8th, 2003 at 11:41 AM.
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2003
    Posts
    804
    Rep Power
    101
    Well the code is kind of cluttered but without really scrutinizing it, it appears that your problem is that the line
    Code:
    window.location = "intro.htm";
    is sending your user to intro.htm without the other script ever running. Try removing this entire section of code:
    Code:
    if (ny=="1" || ny=="2" ){
    // Where do you want the user to go the first two times 
    //he visits your site?
    window.location = "intro.htm";
    }
    It should work then.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    4
    Rep Power
    0

    Talking You're a genius!!


    Thanks for the help! I didn't even think about the fact that I had 2 redirects on the same page - it can only go ONE place, afterall.

    And thanks for not laughing too hard at my "code" attempt.
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2003
    Posts
    804
    Rep Power
    101
    No problem... learning takes practice, after all. I've been in your position before

IMN logo majestic logo threadwatch logo seochat tools logo