Closed Thread Icon

Topic awaiting preservation: Javascript and cookie problems (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=8385" title="Pages that link to Topic awaiting preservation: Javascript and cookie problems (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Javascript and cookie problems <span class="small">(Page 1 of 1)</span>\

 
Milkman
Nervous Wreck (II) Inmate

From: The Dairy Farm in Royal Oak
Insane since: Jun 2001

posted posted 11-11-2002 14:01

After a very long and needed break from all things electronic I am back. And, as usual, I am having a problem with some code. Here is the problem.

I have created a Flash demonstration for a client and they only want people who are logged into their site to be able to view the demo. They want me to check for a Session ID cookie that they set once a user logs in. If the cookie is present, let them view the demo, if they are not, the Flash file will display a reminder for them to log in. I was originally going to call a Javascript from flash an use the FSCommand to set my variable (FromWebSite) but discoverd that this is not supported fully on all platforms/browsers (see here) Flash does support setting a variable by doing the old "?MyVar=MyVarValue" so I decided to try this following code:

code:
<script language="JavaScript" type="text/JavaScript">
<!--
// See if the Session ID cookie exists
if (getCookie('SESSION_ID')==null)
{
// If it does not exist, embed the SWF with the FromWebSite variable set to 0
document.write('<OBJECT classid="clsid :D27CDB6E-AE6D-11cf-96B8-444553540000"');
document.write(' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0" ');
document.write(' ID=Tour WIDTH=760 HEIGHT=480>');
document.write(' <PARAM NAME=movie VALUE="background.swf?FromWebSite=0"><PARAM NAME=menu VALUE=false> <PARAM NAME=quality VALUE=high> ');
document.write(' <EMBED src="background.swf?FromWebSite=0" menu=false quality=high ');
document.write(' WIDTH=760 HEIGHT=480');
document.write(' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">');
document.write(' </EMBED>');
document.write(' </OBJECT>');
}
else
{
// If it does exist, embed the SWF with the FromWebSite variable set to 1
document.write('<OBJECT classid="clsid :D27CDB6E-AE6D-11cf-96B8-444553540000"');
document.write(' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0" ');
document.write(' ID=Tour WIDTH=760 HEIGHT=480>');
document.write(' <PARAM NAME=movie VALUE="background.swf?FromWebSite=1"><PARAM NAME=menu VALUE=false> <PARAM NAME=quality VALUE=high> ');
document.write(' <EMBED src="background.swf?FromWebSite=1" menu=false quality=high ');
document.write(' WIDTH=760 HEIGHT=480');
document.write(' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">');
document.write(' </EMBED>');
document.write(' </OBJECT>');
}
// name - name of the desired cookie
// will return a string containing value of specified cookie or null if the cookie does not exist
function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else
begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1)
end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}
//-->
</script>



This works on everything except Internet Explorer on Windows. I am at a complete loss of what to try next and any help would be appreciated. I have tried to convince the client to use a different method of user authentication other than the cookie one, but they are dead set on this.




[This message has been edited by Milkman (edited 11-11-2002).]

Milkman
Nervous Wreck (II) Inmate

From: The Dairy Farm in Royal Oak
Insane since: Jun 2001

posted posted 11-11-2002 17:36

I should also add what isn't working. (stoopid Milkman)

It will embed the swf file perfectly but is embedding the swf with the variable set to 0 instead of 1 on IE in windows only. When I was using the FSCommand option it detected the Session ID cookie fine and worked fine for windows machines.



« BackwardsOnwards »

Show Forum Drop Down Menu