javascriptjqueryhtmlajaxopenx

document.write on already loaded and closed website


i have a website where news articels are shown.

now i already implemented a ajax reload for the articel so i can switch from one to another without reloading the whole page. (Like in News Apps)

there is a box with advertisment in every articel aswell. This box is filled with an ad which is placed there with document.write. (OpenX)

When i now reaload an articel the content of the box cant be written there because my document is already closed and the new articel is only loaded there with jQuery and AJAX. So when i reaload the articel the content in the document.write cant be written into the box and is instead just placed unter my webseite, which looks likes some kind of error code.

Now my Question is. How can i get the Content into the Box? Is there a away to open a closed document to write it there or do i need to replace all document.write lines with, for example, jQuery append();?

I've already tried to replace some of the parts with jQuery append(); But there i get some problems too, like this one is working fine:

document.write ("<td style='width:100px;'>"); //old
jQuery("#werb1").append("<td style='width:100px;'>"); //new 

But this one doesnt work at all:

document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u); //old
jQuery("#werb1").append("<scr"+"ipt type='text/javascript' src='"+m3_u) //new

m3_u is a URL saved in the varible like https://ad.domain.openx/www/delivery/ajs.php


Solution

  • You cannot pass to already rendered table. You need to rerender whole table and close script tag

    If you are using dynamic content on website you may condier of using ANGULARJS or ReactJS or Meteor

    Here are full sets of tools wich would really help you with building such webapp.

    But atm you need to remove table, build whole HTML in your variables and put it on website. Browsers, even if you would put that TD correctly, will push td or tr outside of table.