-1

How's that for a title!

Once again I find myself stumbling through lines of code that I don't really understand, and in doing so failing at almost every hurdle.

I have a php file xxxxx.php and what I'm trying to do is: from within a javascript function, set the properties of a div, and then execute some more javascript - I'm sure it's easy for someone who understands (but clearly not for me)

This piece of code works fine as it is:

<script type="text/javascript">
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function checkCookie()
{
var username=getCookie("username");
if (username!=null && username!="")
{
alert("Welcome again " + username);
}
else
{
username=prompt("Please enter your name:","");

if (username!=null && username!="")
{
setCookie("username",username,7);
}
}
}
</script>
</head>
<body onload="checkCookie()">
</body>

But then I want to insert this bit of code (which works fine on its own) directly after the 'setCookie' line:

<div style="position:absolute;top:125px;left:-67px;z-index:10000000">
<script src="AC_RunActiveContent.js" type="text/javascript"></script>

<script type="text/javascript">
AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','320','height','220','id','HTIFLVPlayer','src','HTIFLVPlayer','flashvars','&MM_ComponentVersion=1&skinName=HTI_Skin&streamName=nigel&autoPlay=true&autoRewind=true','quality','high','scale','noscale','name','HTIFLVPlayer','salign','lt','pluginspage','http://www.macromedia.com/go/getflashplayer','wmode','transparent','movie','HTIFLVPlayer'); //end AC code

</script> </div>

Any thoughts or suggestions would be greatly appreciated.

I tried setting the div style in javascript using:

var div = document.createElement('div');
div.style.position = 'absolute';
div.style.top = "125px";
div.style.left = "-67px";
div.style.zIndex = "10000000";
document.body.appendChild(div);

...but this simply threw the flash player (called with the 'AC_FL_RunContent' line) onto a new blank page, not within the existing page (as required).

Hopefully someone will be able to make sense of my ramblings.

Rob.

1

1 Answer 1

1

seems like your new code with <div> tag is inside main <head> tag - it won't work, try putting new code inside <body> tag.

another thing, you can't put any html tags inside <script> just like that. you have to document.write them somewhere.

EDIT

use sth like this after setCookie();:

document.write('<div style="position:absolute;top:125px;left:-67px;z-index:10000000">');
document.write('<script src="AC_RunActiveContent.js" type="text/javascript"></script>');
document.write("<script type=\"text/javascript\"> AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','320','height','220','id','HTIFLVPlayer','src','HTIFLVPlayer','flashvars','&MM_ComponentVersion=1&skinName=HTI_Skin&streamName=nigel&autoPlay=true&autoRewind=true','quality','high','scale','noscale','name','HTIFLVPlayer','salign','lt','pluginspage','http://www.macromedia.com/go/getflashplayer','wmode','transparent','movie','HTIFLVPlayer'); //end AC code</script> </div>");

I hope it helps!

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your reply. As I said, I don't actually understand how most of the code I crib and pick up from various sources actually works, and I hear what you're saying, but unfortunately (apologies for being thick) I still don't understand what I actually need to do to get the second bit of code integrated into the first.
insert the second bit of code after <body onload="checkCookie()">. you can't do this directly after setCookie() line, because: 1) you can't mix plain html with plain js and 2) <div> inside <head> won't work
Thanks, I'm starting to understand, but what I'm trying to do is basically play a video in a div, but only if there's no cookie set, so I have to call the code to play the video from within the javascript that checks for the cookie (unless you tell me otherwise), and therefore if I put it in the body, then it always plays. Perhaps there's an easier way of acomplishing what I'm trying to do????
use document.write. I'll edit my answer to make it more readable ; )
Thanks for that. Strangely, the code itself is executed without a problem, but still opens the video on a new page. I'll keep on trying. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.