开发者

Sending data through post method to an iframe

I have an iframe which is pointing to a moodle site. I need to pass to it my username and password, so that when the iframe is loaded, I am automatically logged in on moodle. So I have something开发者_运维技巧 like this:

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

My question is how to send my username and password using POST method to this URL?


To POST to an iframe you must use 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>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜