简体   繁体   English

是否可以使用JavaScript从iFrame外部提交未命名的表单?

[英]Is it possible to use JavaScript to submit an unnamed form from outside an iFrame?

I know that may sound silly, but I'm trying to submit a form on a page inside an iFrame, from the parent site. 我知道这听起来很愚蠢,但是我正在尝试通过父网站在iFrame内的页面上提交表单。

Here's an example of the form: 这是表格的示例:

        <form action="/add_email" method="post"> 
        <div class="field"> 
            <label for="newEmailAddress" style="width: auto">Add new email address</label> 
            <input type="text" id="newEmailAddress" name="email" value="null" class="text-field" /> 
            <input type="hidden" name="__app_key" value="null"/> 
            <input type="submit" value="Add address and send activation email"> 
        </div> 
        </form>

As you can see, the Submit button, and the form itself both lack a proper name or id, this is not something I have control over. 如您所见,“提交”按钮和表单本身都缺少适当的名称或ID,这不是我可以控制的。 (It's on an external website.) (在外部网站上。)

Any suggestions? 有什么建议么?

Since it is an external website — no. 由于它是一个外部网站-不。 The Same Origin Policy prevents it. 同源起源策略阻止了这种情况。

If it was the same website then you could communicate across frames and then access the form via its numerical index in the forms object (but you would also likely be able to give it an id and use that instead). 如果是同一网站,则可以跨框架进行通信 ,然后通过forms对象中的数字索引访问表单 (但您也可以为其指定一个id并使用它)。

When no name is given to the form then form has the default form name in a form of array ie form[] 如果没有为表单指定名称,则form具有数组形式的默认表单名称,即form []

hence one can create as many forms in script, the default name's index will increase. 因此,可以在脚本中创建尽可能多的表格,默认名称的索引将增加。 Hence one can use it accordingly. 因此,人们可以相应地使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM