1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

(请教)怎样把统计代码放在一个js中调用呢?

本帖由 Kevin2007-06-13 发布。版面名称:前端开发

  1. Kevin

    Kevin New Member

    注册:
    2005-10-23
    帖子:
    12,728
    赞:
    55
    暂时想放google analytics:
    代码如下:
    代码:
    <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
    </script>
    <script type="text/javascript">
    _uacct = "UA-63296-3";
    urchinTracker();
    </script>
    比如我调用的js文件为stat.js

    stat.js代码如下:

    代码:
    // JavaScript Document
    document.write ('<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">');
    document.write ('</script>');
    document.write ('<script type="text/javascript">');
    document.write ('_uacct = "UA-63296-3";');
    document.write ('urchinTracker();');
    document.write ('</script>');

    但是调用后页面会有js错误:

    Line:434
    Char:23
    Code:0
    Error:缺少对象

    js不懂,请问这个怎么解决?谢谢!
     
  2. Kevin

    Kevin New Member

    注册:
    2005-10-23
    帖子:
    12,728
    赞:
    55
    请教别人以后,别人叫我stat.js改成下面这样,但是问题依旧,晕倒,帮下忙吧!

    HTML:
    document.write(
    '<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>\
    <script type="text/javascript">\
    _uacct = "UA-63296-3";\
    (function(){\
      try{\
        urchinTracker();\
      }catch(e){\
        setTimeout(arguments.callee,500);\
      }\
    })();\
    </script>'
    );
     
  3. Kevin

    Kevin New Member

    注册:
    2005-10-23
    帖子:
    12,728
    赞:
    55
    :cry::cry::cry:
     
  4. Kevin

    Kevin New Member

    注册:
    2005-10-23
    帖子:
    12,728
    赞:
    55
    没技术真没面子啊,连这个小问题都解决不了!
     
  5. zmnet

    zmnet Well-Known Member

    注册:
    2006-05-03
    帖子:
    7,809
    赞:
    62
    看看修改成这样

    PHP:
    document.writeln("<script src=\"http:\/\/www.google-analytics.com\/urchin.js\" type=\"text\/javascript\">");
    document.writeln("<\/script>");
    document.writeln("<script type=\"text\/javascript\">");
    document.writeln("_uacct = \"UA-63296-3\";");
    document.writeln("urchinTracker();");
    document.writeln("<\/script>");
     
  6. A君

    A君 Well-Known Member

    注册:
    2005-08-31
    帖子:
    19,987
    赞:
    98
    不懂技术的,也来帮你顶一下
     
  7. OUYANG

    OUYANG New Member

    注册:
    2005-09-06
    帖子:
    3,025
    赞:
    5
  8. apple

    apple New Member

    注册:
    2006-05-22
    帖子:
    9,561
    赞:
    78
    哇!都是JS高手来 的!
     
  9. Kevin

    Kevin New Member

    注册:
    2005-10-23
    帖子:
    12,728
    赞:
    55

    :heart:谢谢,马上试试!

    谢谢楼上的几位帮顶!:eek:
     
  10. Kevin

    Kevin New Member

    注册:
    2005-10-23
    帖子:
    12,728
    赞:
    55
    唉,没撤了,还是:
    Line:378
    Char:1
    Code:0
    Error:缺少对象
     
  11. Kevin

    Kevin New Member

    注册:
    2005-10-23
    帖子:
    12,728
    赞:
    55
    唉,没撤了,还是:
    Line:378
    Char:1
    Code:0
    Error:缺少对象
     
  12. Kevin

    Kevin New Member

    注册:
    2005-10-23
    帖子:
    12,728
    赞:
    55
    应该是google analytics本身的问题,晕,应该是故意的!
     
  13. 风云007

    风云007 New Member

    注册:
    2007-06-25
    帖子:
    2
    赞:
    0
    路过!努力学习!