Which one is better to generate responsive ad code for my own Ad Network ? document.write ? or innerhtml?

257 views Asked by At

I'm planning to start an Ad Network from Scratch and I'm studying the market and also I'm trying to find out best ways to deal with the existing issues. I already know google users some code like below to generate the ad contents for the uses using javascript.

(As @crazimoin answered in my previous question)

document.write('<iframe src="http://myadserver.com/showads.php?ad_client='+ ad_client+'&ad_slot='+ad_slot+' margin=0 frameborder=0 scrolling=no allowtransparency=true ></iframe>');

I want to know these things.

  1. Does it slower than using innerhtml method ?
  2. If it is slower than innerhtml is it good to use innerhtml to generate the ad content for the publishers.
  3. Is there any better way to do this with JQuery without losing the performance ?
  4. Do these methods allow me to generate responsive ad content for the users ?
    (To make them responsive I hope I can use bootstrap or my own css)

Update: I came to know that innerhtml is faster than DOM methods according to this benchmarks of DOM and Innerhtml

1

There are 1 answers

7
Madara's Ghost On

Neither.

var adFrame = document.createElement('iframe');
adFrame.src = "....";
adFrame.setAttribute('margin', 0); // Please consider using CSS!
adFrame.setAttribute('frameborder', 0); // Please consider using CSS!
adFrame.setAttribute('scrolling', 'no');
adFrame.setAttribute('allowtransparency', true);

document.body.appendChild(adFrame);

Use element nodes. Gives you much more control without messing with HTML and dangers of XSS.