Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

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


  • #2
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    I gave you this solution because without it you will not be able to add any html object outside the body on runtime.

  • #5
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...

  • #6
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •