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.

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:

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?


<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;
    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();
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());

<iframe src="<script>getCookie(url);</script>" extrastuff="here" onchange="setCookie(url,this.src,1"></iframe>

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.