Rob Sealey
Rob Sealey

Reputation: 131

HTML & Javascript Code within PHP

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.

Upvotes: 0

Views: 266

Answers (1)

maialithar
maialithar

Reputation: 3123

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!

Upvotes: 1

Related Questions