I'm trying to convert our ads code from HTML to Javascript.
Here is the html
<div id="mobile">
<script><![CDATA[
var m3_u = (location.protocol=='https:'?'https://localhost':'http://localhost');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=640&target=_blank");
document.write ('&cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used);
document.write (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : ''));
document.write ("&loc=" + escape(window.location));
if (document.referrer) document.write ("&referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if (document.mmm_fo) document.write ("&mmm_fo=1");
document.write ("'><\/scr"+"ipt>");
]]></script>
</div>
Here is the code modified for javascript files.
FYI:
newelement creates us a new element with the ID mobile and attached to the comments element
var elm=newelement("div",el("comments"),0,"mobile",""); // <div id="mobile"></div>
var m3_u = (location.protocol=='https:'?'https://localhost':'http://localhost');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
var str= "<scr"+"ipt type='text/javascript' src='"+m3_u;
str+="?zoneid=640&target=_blank";
str+='&cb=' + m3_r;
if (document.MAX_used != ',') str+="&exclude=" + document.MAX_used;
str+= (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : ''));
str+= ("&loc=" + escape(window.location));
if (document.referrer) str+="&referer=" + escape(document.referrer);
if (document.context) str+="&context=" + escape(document.context);
if (document.mmm_fo) str+="&mmm_fo=1";
str+="'><\/scr"+"ipt>";
elm.innerHTML=str;
My end goal is to have the javascript code inside the mobile div
to load into the page from the javascript file instead of the html.
I tried appending str
to the innerHTML
of the common-mobile-ad div
i created but that doesn't seem to work.What can I do to resolve this? Is my string concatenation correct?