简体   繁体   English

填写并提交新打开的窗口的表格

[英]Filling out and submitting a form for a newly opened window

What I'd like to do is open a new window, then submit the form in that new window after automatically filling out he form elements from the original window. 我想做的是打开一个新窗口,然后在自动从原始窗口中填写表单元素之后,在该新窗口中提交表单。 Here is what I tried to do: 这是我尝试做的事情:

var username = 'myuser';
var password = 'mypass';
var loginWindow = window.open('http://www.mysite.com/form.html', 'loginWindow');
loginWindow.document.getElementById('username').value=username;
loginWindow.document.getElementById('password').value=password;
loginWindow.document.form.submit();

This however does not work, and instead gives me the following error: "Result of expression 'loginWindow.document' [undefined] is not an object." 但是,这不起作用,而是给我以下错误:“表达式'loginWindow.document'的结果[未定义]不是对象。”

Is this even possible? 这有可能吗? Can jQuery solve this? jQuery可以解决这个问题吗?

You will not be permitted to refer to objects in a document hosted on a different domain to the one the current document was retrieved from. 将不允许您引用与当前文档所引用的域不同的域中托管的文档中的对象。 Are both documents in the same domain? 两个文件都在同一个域中吗? Are you using the 'www' prefix for one but not the other? 您是否在使用“ www”前缀而不是另一个?

If you have to pass information across domains, consider passing it via the URL. 如果您必须跨域传递信息,请考虑通过URL传递信息。 Alternatively, is there any reason not to submit the data yourself directly to the location the target form would be submitting it to? 或者,是否有任何理由不将您自己的数据直接直接提交到目标表单将提交到的位置?

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

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