开发者

Filling out and submitting a form for a newly opened window

开发者 https://www.devze.com 2022-12-13 22:24 出处:网络
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:

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 jQuer开发者_如何转开发y 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?

0

精彩评论

暂无评论...
验证码 换一张
取 消