Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2003
    Location
    Holland
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    different page depending on how many times loaded the page

    Hi all there. I'm stuck with making a js. I found some cool scripts on this site.

    these:
    -alert message that says how many times you've been on the site(http://javascriptkit.com/script/scri...itorinfo.shtml)
    -and another version of this, but thisone says it in the html itself. (http://javascriptkit.com/script/cut13.shtml)

    now i wanted to make a js that does this:
    -when you enter the page for the 1th time, it will say:"hello, you're new here. on the left is a menu etc etc..."
    -when you enter the site for the second time it will say: "hello, welcome back. Do you remember everything that is on this site? here a quick guide etc etc"

    I have this till now:

    <BODY>
    <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 null;
    }
    function SetCookie (name, value) {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (2 < argc) ? argv[2] : null;
    var path = (3 < argc) ? argv[3] : null;
    var domain = (4 < argc) ? argv[4] : null;
    var secure = (5 < argc) ? argv[5] : false;
    document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
    }
    function DisplayInfo() {
    var expdate = new Date();
    var visit;
    expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
    if(!(visit = GetCookie("visit")))
    visit = 0;
    visit++;
    SetCookie("visit", visit, expdate, "/", null, false);
    var message;

    if(visit == 1)
    document.write("1");
    if(visit>= 2)
    document.write("2")


    }
    function ResetCounts() {
    var expdate = new Date();
    expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
    visit = 0;
    SetCookie("visit", visit, expdate , "/", null, false);
    history.go(0);
    }

    window.onload=DisplayInfo
    </Script>
    the part that is written in blue says that when you enter the site for the first time, it will say 1,
    when you enter for the 2nd or more time, it will say 2.

    now the problem is, is that when you enter the site for the first time, you will see a 1. but thats it. when I checked out the source, all i saw was 1 (same for 2nd time, but then I saw a 2).

    Wich means that the body tags above for example don't work. So I figured that, when I post an entire html in the document.write tag it will display a html. BUT also that doesn't work. because body tags for example contain these characters "

    this character also lets the js think that the document.write script ends.........

    so what must I do to make this work!?!?!?!? I don't know it anymore..........

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    if(visit == 1)
    document.write("1");
    if(visit>= 2)
    document.write("2")

    This does what you see - it writes the literal character 1 or 2 depending on the value of visit.

    Try this:-

    if (visit != null) {
    switch (visit) {
    case '1' : url = 'page1.html'; // change these to suit!
    break;
    case '2' : url = 'page2.html';
    break;

    .........and so on if desired

    }
    window.location.href = url;
    }

  • #3
    New to the CF scene
    Join Date
    Jul 2003
    Location
    Holland
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so when I change it it should be like this:

    Code:
    <BODY>
    
    
    <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 null;
    }
    function SetCookie (name, value) {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (2 < argc) ? argv[2] : null;
    var path = (3 < argc) ? argv[3] : null;
    var domain = (4 < argc) ? argv[4] : null;
    var secure = (5 < argc) ? argv[5] : false;
    document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
    }
    function DisplayInfo() {
    var expdate = new Date();
    var visit;
    expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
    if(!(visit = GetCookie("visit"))) 
    visit = 0;
    visit++;
    SetCookie("visit", visit, expdate, "/", null, false);
    var message;
    
    if (visit != null) {
    switch (visit) {
    case '1' : url = 'home.html'; // change these to suit!
    break;
    case '2' : url = 'home2.html'; 
    break;
     
    
    }
    function ResetCounts() {
    var expdate = new Date();
    expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
    visit = 0;
    SetCookie("visit", visit, expdate , "/", null, false);
    history.go(0);
    }
    
    window.onload=DisplayInfo
    </Script>
    if it must be this, then you're wrong. because it doesn't work...
    Last edited by squit; 07-06-2003 at 08:38 PM.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Well, no, it doesn't.

    But it might if you followed what I suggested to you.

    if (visit != null) {
    switch (visit) {
    case '1' : url = 'page1.html'; // change these to suit!
    break;
    case '2' : url = 'page2.html';
    break;
    }
    window.location.href = url;
    }


    This assumes that the variable 'visit' has the values of 1, 2 etc.

  • #5
    New to the CF scene
    Join Date
    Jul 2003
    Location
    Holland
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    DOH! Shame on me.......So I changed it, and it still doesn't work....

  • #6
    New to the CF scene
    Join Date
    Jul 2003
    Location
    Holland
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I know that there's a way to read from an external .js file. that goes like this
    Code:
    <script src="example.js"></script>
    in the .js file you put something like this for example:
    Code:
    document.write("hello")
    when you open the html file, you will see 'hello'

    isn't there a way to combine this script with the one i am making know?? So you get something like this:

    if(visit == 1)
    read from external js file here
    if(visit>= 2)
    read from 2nd external js file here

    how should the tag to read from the js file be??


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •