首页 > 解决方案 > 跨域读取阻止 (corb) 阻止了 mime 类型 text/html 的跨域响应

问题描述

我开发了一个聊天机器人,它将部署在 3rd 方网站上。我编写了一个脚本来检查该脚本中的机器人 ID 和其他参数。如果该参数匹配,则使用加载脚本,insertBefore()但出现上述错误。

最重要的是,编写脚本以在 IFRAME 中加载小部件的好方法是什么?

!(function (a) {
  var b = a.getElementById ('ds-ref-id');
  if (!b) return void console.error ('Ref ID not found');
  var c = b.getAttribute ('rel');
  if (c && 'nofollow' == c.toLowerCase ())
    return void console.error ('rel="nofollow" not allowed');
  var d = b.getAttribute ('href');
  if (d && 'URL.test' != d.toLowerCase ())
    return void console.error (
      'abc reference must point to URL.test'
    );
  var e = b.getAttribute ('data-bot-id');
  if (!e) return void console.error ('abc account id not found');
  var f = b.getAttribute ('title');
  if (!f || (f && '' == f.trim ()))
    return void console.error ('abc reference must have a title');
  var g = b.innerHTML;
  if (!g || (g && '' == g.trim ()))
    return void console.error ('abc reference must have a name');
  var h = a.createElement ('script');
  (h.type = 'text/javascript'), (h.src = `http://IPADDRESS:8080?id=${e}`);
  var i = a.getElementsByTagName ('script')[0];
  i.parentNode.insertBefore (h, i);
}) (document);

标签: javascriptvue.js

解决方案


这是一个常见的错误,您正在尝试使用不在您的域中的东西。

您的引导 vue 已部署在 xx.com 上,并且您的“API”没有启用允许域列表或允许所有域。

简而言之,您的“API”不允许来自 xx.com 的请求。您必须启用它。

更多信息:https ://developer.mozilla.org/en-US/docs/Web/HTTP/CORS


推荐阅读