我有一个 iframe,它指向一个 Moodle 站点。我需要将我的用户名和密码传递给它,以便在加载 iframe 时,我会自动登录到 Moodle。所以我有这样的事情:
<div id="iframe" style="width:787px; height:700px;">
<iframe id="iframeCon" src ="http://www.somesite.net/moodle/login/index.php"
width="100%" height="100%" frameborder="0">
</iframe>
</div>
我的问题是如何使用 POST 方法将我的用户名和密码发送到此 URL?
最佳答案
要发布到 iframe,您必须使用 form target
.
<form id="moodleform" target="iframe"
method="post" action="http://www.example.com/login/index.php" >
<input type="hidden" name="username" value="guest"/>
<input type="hidden" name="password" value="guest"/>
<input type="hidden" name="testcookies" value="1"/>
</form>
<iframe name="iframe"></iframe>
<script type="text/javascript">
document.getElementById('moodleform').submit();
</script>
关于post - 通过 post 方法将数据发送到 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3803320/