我需要通过iFrame自动登录外部网站。我无权在iFrame中对网站进行更改。安全问题超出了该项目的范围。
从功能上讲,它需要像this一样工作。以下是受该链接启发的代码:
HTML
<form id="login" target="frame" method="post" action="foo.com">
<input type="hidden" name="userid" value="username" />
<input type="hidden" name="password" value="password123" />
</form>
<button id="send">Submit</button>
<div>
<iframe id="frame" name="frame" src="https://foo.com"></iframe>
</div>
的JavaScript
$('#send').click(function () {
document.getElementById('login').submit();
});
运行此代码会出现错误,指出url中缺少必需的参数。手动登录不会出错。我没有控制台错误。