2016-03-04 33 views
0

我正在实现一个typeform,我想对它进行一些定制。我希望用户在主页上提交电子邮件地址,并在另一个详细信息页面上填写其他问题。我现在通过网址传递电子邮件地址,但我无法将其发送到TypeForm iframe。谁曾经这样做过?你可以在两页分割一个类型吗?

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

我的网址是这样的:somethinglikethis.com/[email protected]

和jQuery上join.html:

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

我尝试了很多其他的东西为好,但我不能使它工作...

+0

为什么你不把电子邮件ID保存在变量中,然后从iframe中访问它? –

+0

之前尝试过,但它似乎iframe阻止任何JavaScript输入... –

+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和您的主页都在同一个域中,这将起作用。

让我知道这是否有帮助

相关问题