简体   繁体   English

使用JavaScript在iframe中输入数据以形成表单字段

[英]Using Javascript to enter data in to form fields in an iframe

This isn't a "how to" question at this stage, more of a "can I." 这不是现阶段的“如何”问题,更多的是“我可以”。

I am capturing form data on /page1.php - upon submit /page2.php is loaded which contains further form fields that are displayed via an iframe. 我正在/page1.php上捕获表单数据-提交时/page2.php加载完毕,其中包含通过iframe显示的其他表单字段。 The form that is loaded is hosted on another server (just in case that makes a difference). 加载的表单托管在另一台服务器上(以防万一)。

The question I have is; 我的问题是; Is there anyway of using javascript (or any other language) to autofill a field that is in the iframe? 无论如何,是否使用javascript(或其他任何语言)自动填充iframe中的字段?

I hope that makes sense but if anyone needs any clarification, please let me know. 我希望这是有道理的,但是如果有人需要澄清,请告诉我。

thanks 谢谢

This part is important: 这部分很重要:

The form that is loaded is hosted on another server (just in case that makes a difference). 加载的表单托管在另一台服务器上(以防万一)。

That makes a big difference, here's why: 这有很大的不同,原因如下:

"The same-origin policy restricts how a document or script loaded from one origin can interact with a resource from another origin." “同源策略限制了从一个来源加载的文档或脚本如何与另一个来源的资源进行交互。” https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy

You can try to use some Ajax to interact between the pages. 您可以尝试使用一些Ajax在页面之间进行交互。

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

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