简体   繁体   中英

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.

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. (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).

When no name is given to the form then form has the default form name in a form of array ie form[]

hence one can create as many forms in script, the default name's index will increase. Hence one can use it accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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