...

View Full Version : IE7 JavaScipt Cookie from protected directory



AgentX
08-31-2007, 04:33 PM
I use the Deconcept swfObject JavaScript method to dynamically embed Flash content on my site (serving alternative content when required etc.)

I added something to the script so that it first looks for a cookie on the visitor's computer to determine whether they have elected to view Flash content or not. If it finds the cookie it shows the non-Flash content.

This has been working fine for several years and still does - example: http://www.pennymachines.co.uk/Museum/Allwins-1.shtml
(Click red Flash icon to hide Flash)

However, a problem arose when IE7 arrived. BUT it only affects pages that are served from a directory which is protected by a Perl script (membership subscriber pages).

If you want to check this out use the temporary Username and Password - codingforums and visit this page: http://www.pennymachines.co.uk/.Arena/CSI-1.shtml

IN IE7 you get a "JavaScript required for slideshow" message in the middle of the page (plus alternative content).
Notice - it does not effect the Flash navigation on the left, just the protected page in the main frame.
In Firefox you'll get the Flash slideshow as intended.

The problem seems to be with the cookie retrieval because if I remove that from the script it works fine.

Sounds complicated, I know. I'm just a JavaScript muddler - so maybe someone who understands this stuff can suggest a possible cause or cure.

Here's the JS I added to swfObject:

//Flashtoggle begins
function makeCookie(name, value, expire) {
document.cookie = name + "=" + escape(value)
+ ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}
function getCookie(Name) {
var search = Name + "="
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset)
if (end == -1)
end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
}
}
function flashOff(name) {
var today = new Date()
var expires = new Date()
expires.setTime(today.getTime() + 1000*60*60*24*365)
makeCookie("flashtoggle", name, expires)
}
function flashOn(name)
{
flashOff(name,"",-1);
}
var cookie1 = getCookie("flashtoggle");
//Flashtoggle ends


And in the HTML:

<p id="flashcontent">my non-Flash content</p>
<script type="text/javascript">
if (cookie1 != "flashtoggle"){
// <![CDATA[
var so = new SWFObject("slideshow.swf", "slideshow.swf", 390, 540, 6,0,29,0);
so.write("flashcontent");}
// ]]>
//--></script>

_Aerospace_Eng_
09-01-2007, 08:23 AM
Change this

<script type="text/javascript">
if (cookie1 != "flashtoggle"){
// <![CDATA[
var so = new SWFObject("slideshow.swf", "slideshow.swf", 390, 540, 6,0,29,0);
so.write("flashcontent");}
// ]]>
//--></script>
to this

<script type="text/javascript">
if (cookie1 != "flashtoggle"){
var so = new SWFObject("slideshow.swf", "slideshow.swf", 390, 540, 6,0,29,0);
so.write("flashcontent");
}
</script>

AgentX
09-01-2007, 06:22 PM
Many thanks for your reply.

I've updated the page to match your code, but sad to report, it made no difference.

It's very odd that it works fine on Firefox and IE6 (I believe) and it also works fine in IE7 from all directories of my site except this password protected one.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum