最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

firefox - javascript syntax error expected expression, got '<' - Stack Overflow

programmeradmin2浏览0评论

so I have this code:

;
(function (g) {
  var d = document, i, am = d.createElement('script'), h = d.head || d.getElementsByTagName("head")[0], aex = {
    "src": '',
    "type": "text/javascript",
    "async": "true",
    "data-vendor": "acs",
    "data-role": "gateway"
  };
  for (var attr in aex) {
    am.setAttribute(attr, aex[attr]);
  }
  h.appendChild(am);
  g['acsReady'] = function () {
    var aT = '__acsReady__', args = Array.prototype.slice.call(arguments, 0), k = setInterval(function () {
      if (typeof g[aT] === 'function') {
        clearInterval(k);
        for (i = 0; i < args.length; i++) {
          g[aT].call(g, function (fn) {
            return function () {
              setTimeout(fn, 1)
            };
          }(args[i]));
        }
      }
    }, 50);
  };
})(window);

when you run it through the console in Firefox, it'll plain

"SyntaxError: expected expression, got '<'"

However, when you try it out in .html, it works just fine...

what does it do wrong?

so I have this code:

;
(function (g) {
  var d = document, i, am = d.createElement('script'), h = d.head || d.getElementsByTagName("head")[0], aex = {
    "src": '',
    "type": "text/javascript",
    "async": "true",
    "data-vendor": "acs",
    "data-role": "gateway"
  };
  for (var attr in aex) {
    am.setAttribute(attr, aex[attr]);
  }
  h.appendChild(am);
  g['acsReady'] = function () {
    var aT = '__acsReady__', args = Array.prototype.slice.call(arguments, 0), k = setInterval(function () {
      if (typeof g[aT] === 'function') {
        clearInterval(k);
        for (i = 0; i < args.length; i++) {
          g[aT].call(g, function (fn) {
            return function () {
              setTimeout(fn, 1)
            };
          }(args[i]));
        }
      }
    }, 50);
  };
})(window);

when you run it through the console in Firefox, it'll plain

"SyntaxError: expected expression, got '<'"

However, when you try it out in http://esprima/demo/validate.html, it works just fine...

what does it do wrong?

Share Improve this question asked Dec 2, 2015 at 22:59 pillarOfLightpillarOfLight 9,01216 gold badges61 silver badges91 bronze badges 3
  • I just run in Google Chrome's console and Firefox console and it's works. – caballerog Commented Dec 2, 2015 at 23:18
  • In Firefox its apparently different – frontend_dev Commented Dec 2, 2015 at 23:21
  • chrome silently ignores it but on firefox it still will make the network request as @frontend_dev mentioned – enjoylife Commented Dec 2, 2015 at 23:23
Add a ment  | 

1 Answer 1

Reset to default 4

I think this line is problematic:

"src": '',

So you have in essence a blank src. The error itself indicates that you get some HTML in response, in this case apparently the browser just tries to load the page you are currently on (watch the network panel). But try to use something more meaningful with your src, or leave it out pletely if you just want to create a script tag.

发布评论

评论列表(0)

  1. 暂无评论