【问题标题】:Log where a PHP site is iframed from to a file将 PHP 站点的 iframe 记录到文件的位置
【发布时间】:2021-09-09 16:58:18
【问题描述】:

我制作了一个简单的 iframe 小部件,人们可以将它放在他们的网站上,以分享我们国家发生的一件事情:

<div style="width:100%; display:flex; justify-content:center;"><iframe src="//tobia-web.wz.cz/promoravu/embed/" style="border:none; margin-top:25px; border-radius:10px;" height="150" width="300"></iframe></div>

iframe 中的网站使用 PHP。
我想记录 iframe 出现的位置并在单独的文件中加载,因此该文件将包含从 iframe 中加载网站的所有 URL。
我知道你可以detect it,有办法记录吗?

【问题讨论】:

  • 一旦 JS 检测到 PHP 小部件在 iframe 中运行,让 JS 将XmlHttpRequest 发送回 PHP。
  • 哦哇 ajax 超出了我的技能范围

标签: javascript php html iframe


【解决方案1】:

是这样的:

if (iframeDetected) {
  let xhr = new XMLHttpRequest();  // AJAX isn't even a sound acronym
  xhr.open('POST', your_url, true);  // true for asynchronous
  xhr.responseType = 'text';  // sets HTTP headers
  xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');  // let PHP know you're sending from JS
  xhr.formData = new FormData();  // ends up in $_POST
  formData.append('iframeused', true);  // thus $_POST['iframeused']
  req.send(formData);  // fire and forget
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-15
    • 1970-01-01
    • 2011-02-28
    相关资源
    最近更新 更多