js 文件里写 js 代码问题 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
请不要在回答技术问题时复制粘贴 AI 生成的内容
a7898585

js 文件里写 js 代码问题

  •  
  •   a7898585 Sep 17, 2014 4590 views
    This topic created in 4242 days ago, the information mentioned may be changed or developed.
    做了个小站,申请的谷歌和百度的广告,
    放到js文件中后,用document.write来写的,但是前台就是不出现,请帮忙看下是哪里出错了?

    document.writeln("<\script src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!-- 970*250 -->
    <ins class="adsbygoogle"
    style="display:inline-block;width:970px;height:250px"
    data-ad-client="ca-pub-9055653551438880"
    data-ad-slot="7443996645"></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>");
    6 replies    2014-09-19 09:55:22 +08:00
    sneezry
        1
    sneezry  
       Sep 17, 2014
    var ga = document.createElement("script");
    ga.src = "//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";
    document.getElementsByTagName("head")[0].appendChild(ga);

    var ins = document.createElement("ins");
    ins.className = "adsbygoogle";
    ins.style = "display:inline-block;width:970px;height:250px";
    ins.setAttribute("data-ad-client", "ca-pub-9055653551438880");
    ins.setAttribute("data-ad-slot", "7443996645");
    document.getElementsByTagName("body")[0].appendChild(ins);

    (adsbygoogle = window.adsbygoogle || []).push({});



    虽然不知道楼主为啥不直接写进HTML,但是楼主的写法太尼玛凶残了……
    kmvan
        2
    kmvan  
       Sep 17, 2014
    为啥要这样写,就算是 document.write ,也会堵塞页面的
    acecode
        3
    acecode  
       Sep 18, 2014
    document.write才对吧
    另外 浏览器检查 script标签内容的时候看到</script>会当做脚本定义完毕
    参照 h5bp 的做法,字符串里应该用这个 <\/script>
    hkongm
        4
    hkongm  
       Sep 18, 2014
    async或者defer下吧

    另外,小声的说下,楼主是不是忘了关adb?
    a7898585
        5
    a7898585  
    OP
       Sep 18, 2014
    @sneezry
    @hkongm
    @acecode
    @kmvan
    改好了,谢谢各位
    document.writeln('<script src="http://www.v2ex.com//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></scr'+'ipt>'
    +' <!-- 970*250 -->'
    +' <ins class="adsbygoogle"'
    +' style="display:inline-block;width:970px;height:250px"'
    +' data-ad-client="ca-pub-9055653551438880"'
    +' data-ad-slot="7443996645"></ins>'
    +' <script>'
    +' (adsbygoogle = window.adsbygoogle || []).push({});'
    +' </scr'+'ipt>');
    cdxem713
        6
    cdxem713  
       Sep 19, 2014
    这写法还是够奇葩
    About     Help     Advertise     Blog     API     FAQ     Solana     2933 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 48ms UTC 15:11 PVG 23:11 LAX 08:11 JFK 11:11
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86