0

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&amp;target=_blank");
    document.write ('&amp;cb=' + m3_r);
    if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
    document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
    document.write ("&amp;loc=" + escape(window.location));
    if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
    if (document.context) document.write ("&context=" + escape(document.context));
    if (document.mmm_fo) document.write ("&amp;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&amp;target=_blank";
    str+='&amp;cb=' + m3_r;
    if (document.MAX_used != ',') str+="&amp;exclude=" + document.MAX_used;
    str+= (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
    str+= ("&amp;loc=" + escape(window.location));
    if (document.referrer) str+="&amp;referer=" + escape(document.referrer);
    if (document.context) str+="&context=" + escape(document.context);
    if (document.mmm_fo) str+="&amp;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?

somejkuser
  • 8,656
  • 19
  • 58
  • 122

0 Answers0