#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    1
    Rep Power
    0

    Question Script to save iframe source (cookie?)


    hi,

    i would be very very grateful if someone can help me out here.

    i a iframe on my webpage, who's src location if the same domain. as in my other page under the same domain.

    what i'd like to do is when a visitor leaves my site, i want the src of the iframe to be saved and when the same visitor visits the site. that last src will load within that iframe.

    is this possible.

    many many thanks.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    10
    Rep Power
    0
    Depending on ur website if it is just html or is php you can use
    w3schools
    http://www.w3schools.com/JS/js_cookies.asp
    which has some snippets
    in said snippets has a getCookie(c_name) function
    which you can use to get the cookie you are looking for...
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function getCookie(c_name)
    {
    if (document.cookie.length>0)
      {
      c_start=document.cookie.indexOf(c_name + "=");
      if (c_start!=-1)
        {
        c_start=c_start + c_name.length+1;
        c_end=document.cookie.indexOf(";",c_start);
        if (c_end==-1) c_end=document.cookie.length;
        return unescape(document.cookie.substring(c_start,c_end));
        }
      }
    return "";
    }
    
    function setCookie(c_name,value,expiredays)
    {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
    }
    </script>
    </head>
    
    <body>
    <iframe src="<script>getCookie(url);</script>" extrastuff="here" onchange="setCookie(url,this.src,1"></iframe>
    </body>
    </html>
    
    i'm hoping you get the idea...
    i havn't tested the above coding but i'm sure you can figure what is going on there.

IMN logo majestic logo threadwatch logo seochat tools logo