Passing URL parameter in iframe issue

跟風遠走 提交于 2020-04-28 22:43:30

问题


ser goes to 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

I want to pass url parameter as input to 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>

Basically I want to pass value of code from line 4 to input as string in line 9.

Thank you for your time and consideration.


回答1:


I think your question is a duplicate of this question.

You can see a working example I made on Glitch

You can edit here.

Steps to reproduce:

  1. Include Typeform Embed SDK in your HTML
  2. Extract parameters from URL

    let params = new URLSearchParams(location.search);

  3. Reconstruct your form URL

    url += "?utm_source=" + params.get('utm_source');
    
  4. Display form in a target div

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

Hope it helps :)



来源:https://stackoverflow.com/questions/61052520/passing-url-parameter-in-iframe-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!