SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot BoomPop's Avatar
    Join Date
    Aug 2001
    Location
    Missouri, USA
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to make a cookie that correctly sets iFrame src on page load?

    I have an embedded video set in an iFrame (the page is called on.php). When someone clicks the stop video button, the iframe is re-directed to off.php, and the video is replaced with a play video button -- which when clicked takes them back to the video (on.php).



    What I want to do is install a cookie that will permanently 'remember' which page the user has selected (on.php or off.php)... and then from that point forward will always load the appropriate page.

    I've seen all sorts of tutorials about setting cookies and stuff, but nothing that would clue me in on how to accomplish what I'm trying to do specifically.

    Hoping someone can help.

  2. #2
    SitePoint Zealot BoomPop's Avatar
    Join Date
    Aug 2001
    Location
    Missouri, USA
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm... nobody has any ideas?

    I found the code below on another website, but my Javascript skills aren't what they should be. I'm not sure what's going on here, and how to implement it. The thing that confuses me most about this code is:
    <script>getCookie(url);</script>

    Based on code in the <head> I'm not sure how (or if) it's pulling the correct URL.

    Anyone care to take a stab at it? Or share some pointers?

    Thanks.
    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>

  3. #3
    SitePoint Zealot BoomPop's Avatar
    Join Date
    Aug 2001
    Location
    Missouri, USA
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Last try before the weekend.

    Anyone have any pointers RE: the above code?

    Or even better... anyone ever solve this problem before? I'd love to get my hands on a solution.


Bookmarks

Posting Permissions

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