将javascript移动到tag div id

时间:2013-03-28 03:58:03

标签: javascript

我正在玩javascript嵌入式,我从我的服务器获取的代码javascript,代码javascript将生成横幅。

我服务器的javascript示例是:

<script type='text/javascript'>
    <!--//<![CDATA[
    var m3_u = (location.protocol=='https:'?'https://203.130.226.231/advediax/www/delivery/ajs.php':'http://203.130.226.231/advediax/www/delivery/ajs.php');
    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=1");
    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 id banner。

<div id="banner">For banner</div>

<script>
// Possible to move script from my server into tag banner?
// If yes, how to do it?
</script>

条件html现在大致如下:

 <!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <script type='text/javascript'>
            <!--//<![CDATA[
            var m3_u = (location.protocol=='https:'?'https://203.130.226.231/advediax/www/delivery/ajs.php':'http://203.130.226.231/advediax/www/delivery/ajs.php');
            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=1");
            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 id="banner"> </div>
    </body>
</html>

我想如下:

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <div id="banner">
            <script type='text/javascript'>
            <!--//<![CDATA[
            var m3_u = (location.protocol=='https:'?'https://203.130.226.231/advediax/www/delivery/ajs.php':'http://203.130.226.231/advediax/www/delivery/ajs.php');
            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=1");
            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>
    </body>
</html>

在问题中我无法将我的脚本插入并粘贴到div id banner,因为其他人拥有的内容。所以我只是拥有主要的javascript。 我的问题,可以将javascript从我的服务器移动到tag div id banner吗?

由于

2 个答案:

答案 0 :(得分:1)

document.getElementById('banner').innerHTML = 'script string (including tags)';

答案 1 :(得分:-1)

如果您使用jQuery,则可以使用:

jQuery.getElementByID("banner").text(*Insert your code here*);