Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-22-2009, 09:50 PM   PM User | #1
kipdlid
New to the CF scene

 
Join Date: Jul 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
kipdlid is an unknown quantity at this point
Unhappy Problem - please help

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;
}
}

kipdlid is offline   Reply With Quote
Old 07-22-2009, 10:26 PM   PM User | #2
ckeyrouz
Senior Coder

 
ckeyrouz's Avatar
 
Join Date: Jun 2009
Location: Montreal, Canada
Posts: 1,044
Thanks: 5
Thanked 179 Times in 179 Posts
ckeyrouz is on a distinguished road
Try the following :
on the place you want to add your div create an empty div like this:
Code:
<div id="zDiv"></div>
and make your function like this:
Code:
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.
ckeyrouz is offline   Reply With Quote
Old 07-22-2009, 10:40 PM   PM User | #3
kipdlid
New to the CF scene

 
Join Date: Jul 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
kipdlid is an unknown quantity at this point
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.
kipdlid is offline   Reply With Quote
Old 07-22-2009, 10:58 PM   PM User | #4
ckeyrouz
Senior Coder

 
ckeyrouz's Avatar
 
Join Date: Jun 2009
Location: Montreal, Canada
Posts: 1,044
Thanks: 5
Thanked 179 Times in 179 Posts
ckeyrouz is on a distinguished road
I gave you this solution because without it you will not be able to add any html object outside the body on runtime.
ckeyrouz is offline   Reply With Quote
Old 07-23-2009, 04:58 AM   PM User | #5
kipdlid
New to the CF scene

 
Join Date: Jul 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
kipdlid is an unknown quantity at this point
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...
kipdlid is offline   Reply With Quote
Old 07-25-2009, 08:20 PM   PM User | #6
kipdlid
New to the CF scene

 
Join Date: Jul 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
kipdlid is an unknown quantity at this point
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...
kipdlid is offline   Reply With Quote
Reply

Bookmarks

Tags
dom, javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:35 PM.


Advertisement
Log in to turn off these ads.