I have a <div> tag that exists on an asp page. I have written javascript code to move into that div an ad that I randomly pull from a database. The div tag looks like this:
I have a javascript routine that returns all divs that have a 'pos' prefix:
The POSServing is the routine that uses the recordset to return the appropriate ad from the database.
I do a document.write('<%=link%>') to return the ad. This works most of the time unless I have a flash ad that consists of javascript. Then, the ad doesn't layer on the page correctly. Here is the setLyr code.
In FireFox, the ad will display as if I didn't have Flash installed because of the <NOSCRIPT> tags. In IE, I just can't position the ad correctly. The ad will display after the body of the page instead of within it.
Has anyone experienced anything similiar to this? I am pretty new to javascript and I am at a lost. Thanks!
Code:
<div id="pos-SKY"></div>
I have a javascript routine that returns all divs that have a 'pos' prefix:
Code:
var posArray2 = new Array();
var posdivs = document.getElementsByTagName("div");
var divName;
for (var i = 0; i < posdivs.length; i++) {
if (posdivs[i].getAttribute('id') != null && posdivs[i].getAttribute('id').match('pos-')) {
posArray2[posArray2.length] = posdivs[i].getAttribute('id');
divName =posdivs[i].getAttribute('id');
divName2 = divName.replace("pos-", "");
idName = "ad-" + divName2;
idContent = "content-" + divName2;
idClass = "class-" + divName2;
document.write('<div id="' + idContent + '"><div id="'+ idName + '" style="position:absolute"><script type="text/javascript">POSServing("' + divName2 + '");setLyr("' + divName + '","' + idName + '","' + idContent + '");</script></div></div> ');
}
}
I do a document.write('<%=link%>') to return the ad. This works most of the time unless I have a flash ad that consists of javascript. Then, the ad doesn't layer on the page correctly. Here is the setLyr code.
Code:
function setLyr(obj,lyr,container)
{
var o = xGetElementById(obj);
var newX = findPosX(o);
var newY = findPosY(o);
var leftcontainer1= findPosX(xGetElementById(container));
var x = xGetElementById(lyr);
x.style.top = newY + 'px';
newX= newX - leftcontainer1;
x.style.margin = '0 0' + newX + 'px 0';
}
function findPosX(obj)
{
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;
}
function findPosY(obj)
{
var curtop = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curtop += obj.offsetTop
obj = obj.offsetParent;
}
}
else if (obj.y)
curtop += obj.y;
return curtop;
}
function xGetElementById(e) {
if(typeof(e)!="string") return e;
if(document.getElementById){
e=document.getElementById(e);
}
else if(document.all) e=document.all[e];
else if(document.layers) e=xLayer(e);
else e=null;
return e;
}
function xLayer(id,root) { // only for nn4
var i,layer,found=null;
if (!root) root=window;
for(i=0; i<root.document.layers.length; i++) {
layer=root.document.layers[i];
if(layer.id==id) return layer;
if(layer.document.layers.length) found=xLayer(id,layer);
if(found) return found;
}
return null;
}
function xShow(e) {
if(!(e=xGetElementById(e))) return;
if(e.style && xDef(e.style.visibility)) e.style.visibility='inherit';
else if(xDef(e.visibility)) e.visibility='show';
}
function xHide(e) {
if(!(e=xGetElementById(e))) return;
if(e.style && xDef(e.style.visibility)) e.style.visibility='hidden';
else if(xDef(e.visibility)) e.visibility='hide';
}
In FireFox, the ad will display as if I didn't have Flash installed because of the <NOSCRIPT> tags. In IE, I just can't position the ad correctly. The ad will display after the body of the page instead of within it.
Has anyone experienced anything similiar to this? I am pretty new to javascript and I am at a lost. Thanks!