你能在两个页面中拆分一个类型吗?

时间:2016-03-04 14:39:23

标签: javascript jquery html forms

我实现了一个字体,我想稍微自定义一下。我希望用户在主页上提交他们的电子邮件地址,并在另一个详细页面上完成其他问题。我现在通过网址传递电子邮件地址,但我无法将其发送到TypeForm iframe。以前做过这个的人吗?

<form class="form-inline" action="join.html" method="GET">
  <div class="form-group">
        <input type="text" class="form-control" id="exampleInputEmail2" placeholder="angel.investor@example.com" name="email">
  </div>
  <input type="submit" class="btn btn-default reverse" value="Join now!"></input>
</form>

我的网址是这样的:somethinglikethis.com/join.html?email=john.doe@something.com

和join.html上的jQuery:

$("div.typeform-widget div.input input[type='text']").val(window.location.search);
    $('iframe').css('display', 'none');

我也尝试了很多其他的东西,但我无法让它发挥作用......

1 个答案:

答案 0 :(得分:0)

所以我们的想法是,在JavaScript变量中设置电子邮件,然后从iframe中访问变量并将其设置为iframe的隐藏字段。

要将变量保存到JavaScript全局范围,请执行此操作。

$('form[action="join.html"]').on('submit',function(){
   window.ClientEmailId = $('#exampleInputEmail2').val(); 
//save the email id into a variable in the window scope (global scope)      
});

然后在你的iframe中你可以提取如下的值,

var emailId = parent.window.ClientEmailId;
// you can save to any hidden input and use this value further

您需要从iframe父级开始,该父级将是主窗口,然后从那里访问该值。

注意:如果iframe和您的主页都在同一个域下,这将有效。

如果有帮助请告诉我

相关问题