...

View Full Version : Problem - please help



kipdlid
07-22-2009, 10:50 PM
I am trying to add in a div before a script element in my page. Please do not give me easier alternatives because I have tried alot of different thing.
So basically we are looking at adding a div before the script tag then using innerHTML to describe the div's content... I am not skilled in javascript I just put this together from scrap pieces on javascript on the internet... PLEASE HELP :)
code so far
var scripttags = document.getElementsByTagName('script');
for(var i=0; i<scripttags.length; i++)
{
if(scripttags[i].src == 'http://kipdlid.fatcow.com/templatefiles/?ad=1')
{
var horizRule = document.createElement('div');
var paragraph = scripttags[i].firstChild;
horizRule.innerHTML = 'dddwdwdwddwdss';
scripttags[i].insertBefore( horizRule, paragraph );


break;
}
}

ckeyrouz
07-22-2009, 11:26 PM
Try the following :
on the place you want to add your div create an empty div like this:

<div id="zDiv"></div>

and make your function like this:


function addDiv()
{
var scripttags = document.getElementById("zDiv");
var horizRule = document.createElement('div');
var newT = document.createTextNode("dddwdwdwddwdss");
horizRule.appendChild(newT);
scripttags.parentNode.replaceChild(horizRule,scripttags);
}


The purpose of this method is not to inser Before but to replace an empty div with the div you have created in your function.


So for that create and empty div at the place you want, give it an id and replace it with anything you want.

kipdlid
07-22-2009, 11:40 PM
Thats not really what I'm looking for... I am trying to use this for all of my advertisements quick and easy to change from an outside javascript file. The problem is getting the ad to display where I put the script file without interrupting my other content like what document.write does... Any ideas would be great... and if you could fix the java script I made.

ckeyrouz
07-22-2009, 11:58 PM
I gave you this solution because without it you will not be able to add any html object outside the body on runtime.

kipdlid
07-23-2009, 05:58 AM
Are you sure... I'm basically trying to create an alternative to document.write the long way so that it doesnt have all the errors. I need the element or ad to be written inside the page where the javascript file is placed. Does anyone know how it can work without document.write...:confused:

kipdlid
07-25-2009, 09:20 PM
Are you sure... I'm basically trying to create an alternative to document.write the long way so that it doesnt have all the errors. I need the element or ad to be written inside the page where the javascript file is placed. Does anyone know how it can work without document.write...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum