在 iframe 问题中传递 URL 参数

Passing URL parameter in iframe issue

ser 转到 http://yoursite.com/your-typeform-page?code=1 using a browser, that page needs to add a IFRAME with url as data-url=https://yoursite.typeform.com/to/U5aOQR?code=1

我想将 url 参数作为输入传递给 iFrame。

<script>
 queryString = window.location.search;
var urlParams  = new URLSearchParams(queryString);
var code = urlParams.get('code')

 </script>

  <div class="typeform-widget" data-url="https://yoursite.typeform.com/to/U5aOQR?code"+ code 
 style="width: 100%; height: 500px;"></div>
<script> (function() { var qs,js,q,s,d=document,gi=d.getElementById, ce=d.createElement, gt=d.getElementsByTagName, id="typef_orm", b="https://embed.typeform.com/"; if(!gi.call(d,id)) { js=ce.call(d,"script"); js.id=id; js.src=b+"embed.js"; q=gt.call(d,"script")[0]; q.parentNode.insertBefore(js,q) } })() </script>

 </div>

基本上我想将代码的值从第 4 行传递到第 9 行中作为字符串输入。

感谢您的时间和考虑。

我认为您的问题与 重复。

你可以看到我在 Glitch

上制作的 working example

您可以编辑 here

重现步骤:

  1. 在您的 HTML
  2. 中包含 Typeform Embed SDK
  3. 从URL

    中提取参数

    let params = new URLSearchParams(location.search);

  4. 重构你的表单URL

    url += "?utm_source=" + params.get('utm_source');
    
  5. 在目标中显示表单div

    window.typeformEmbed.makeWidget(
      embedElement,
      url, 
      {
        hideHeaders: true,
        hideFooter: true,
      }
    );```
    

希望对您有所帮助:)