简体   繁体   中英

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."

Is this even possible? Can jQuery solve this?

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?

If you have to pass information across domains, consider passing it via the URL. Alternatively, is there any reason not to submit the data yourself directly to the location the target form would be submitting it to?

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