I need to find the most correct way to display and execute an advertising banner inside a div with this format:
<div id="1111-1"><script src="//ads.website.com/s/gen.js?type=2"></script><script src="//ads.website.com/s/requestform.js?siteId=1111&formatId=2"></script></div>
I have prepared a div with:
<div class="myclass" id="myid"></div>
but I can't execute anything. I've tried:
let element = document.getElementById('adsmoneytizer').innerHTML = app.forum.attribute('adscode') || "";
eval(element);
where app.forum.attribute return the string "<div id="1111-1"><script src="//ads.website.com/s/gen.js?type=2"></script><script src="//ads.website.com/s/requestform.js?siteId=1111&formatId=2"></script></div>"
How can I display and execute this code?
You should be appending element to the body for the script to execute:
let element = document.createElement('div')
element.innerHTML = app.forum.attribute('adscode') || "";
document.body.appendChild(element)
you should use eval() instead to make it works
$(this.node).find('script').each(function(index, element) {
eval(element.innerHTML);