12

我有一个指向 moodle 站点的 iframe。我需要将我的用户名和密码传递给它,以便在加载 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?

4

1 回答 1

30

要发布到 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>
于 2010-09-27T11:32:15.343 回答