如何检查嵌入了 JavaScript 徽章的网站?

发布于 2024-07-09 03:14:35 字数 198 浏览 6 评论 0原文

我希望允许用户使用一段 JavaScript 代码将徽章嵌入到他们的个人网站或博客中。 该徽章是根据他们的个人资料中的信息在我们的网站上定制的,这些信息在某些时候是“批准的”。

是否有最佳实践来检查 javascript 嵌入在哪个网站上,如果它与“已批准”配置文件中的网站不匹配,则不显示任何内容。 如果匹配则注入 html 等。

谢谢

I want to allow users to embed badges on their personal site or blogs with a snippet of javascript. The badge is customized on our site based on information in their profiles that at some point is "approved".

Is there a best practice to check what website the javascript is embedded on and if it does not match the website in their "approved" profile display nothing. If it matches inject the html etc.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

很酷不放纵 2024-07-16 03:14:35

立即想到两种方法:

  1. 配置您的服务器以记录所有 javascript 请求的“Referer”标头
    甚至根据批准的 url 列表进行检查,并返回错误代码 (403 Forbidden 看起来像是赢家)。

  2. 让 Javascript“打电话回家” - 报告它在哪里 - 像这样:

    var etCallHome = new Image(); 
      etCallHome = "http://yoursite.com/logger?url="+document.location.href; 
      

您也可以将这两种方法结合起来以获得运气。 :-)

Two methods come to mind immediately:

  1. Configure your server to log the "Referer" header of all requests for the javascript
    and even check it against a list of approved urls, and return an error code (403 Forbidden looks like a winner).

  2. Have the Javascript "call home" - reporting where it is - like so:

    var etCallHome = new Image();
    etCallHome = "http://yoursite.com/logger?url="+document.location.href;
    

You could also combine both approaches for luck. :-)

夏九 2024-07-16 03:14:35

您可以使用以下命令检查顶部网址:

var topUrl = top.location.href;

You could check the top url using:

var topUrl = top.location.href;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文