4

need some help on the below, as, unfortunately, I am unable to figure it out by myself :(

  1. User gets redirected to a form (served via an iframe) which includes a dynamic URL: website.com/form?id=123

  2. The code which serves up the page reads that value ("123") from the “id” parameter in the page’s URL.

  3. The script then writes that value on the end of the URL in the “data-url” attribute, like in the example code snippet below.

<div class="typeform-widget" data-url="iframe.com/to/abc123?id=123" 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.iframe.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>

Unfortunately, I cannot seem to get it to work...

Thanks much!

4
  • Got stuck on parsing the id from the URL... Commented Nov 3, 2017 at 16:31
  • Is this code executing inside the frame? Is it trying to read the current browser url or iframe url? Commented Nov 4, 2017 at 4:54
  • The code is on the site (not the iframe), but aims at changing the iframe url by reading the id tag in the current browser url Commented Nov 4, 2017 at 17:32
  • So if I understand it right, user goes to "website.com/form?id=123" using a browser, that page needs to add a IFRAME with url as iframe.com/to/abc123?id=123? do you have a sample nonworking live page also? Commented Nov 4, 2017 at 17:35

1 Answer 1

12
+50

Not sure why you are facing issue with this task. Below is how I would get the ID from the current URL

url = document.location.href;
var paramId = new URL(url).searchParams.get("id");

var frameElement = document.getElementById("typef_orm_frame");
frameElement.src = "https://example.com/to/abc" + paramId + "?id=" +paramId;

Here is the JSFiddle for the demo

https://jsfiddle.net/0Lswuxj8/1/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.