manage iframe's form submit from parent frame?

蹲街弑〆低调 提交于 2020-01-03 03:12:28

问题


I want to change the submit function of form in iframe from the parent frame. The following code should do that, but nothing hapen. And no error shown in chrome's debugger. What is wrong?

<iframe src="test.php" id="frame"></iframe>

<script type="text/javascript">
$("#frame").contents().find("form").submit(function(){
    return true;
});
</script>

回答1:


Make sure that you are manipulating the DOM of this iframe once its contents has been loaded by wrapping your call inside a .load callback:

<iframe src="test.php" id="frame"></iframe>

<script type="text/javascript">
    $('#frame').load(function() {
        $(this).contents().find('form').submit(function() {
            return false;
        });
    });
</script>



回答2:


You cannot manipulate any of the actions of an iFrame through JS.

That is the whole point of an iFrame.

Try today, try forever. It cannot be done. That is why Facebook "like" buttons and many other big-league items are always contained withing iFrames, so you cannot change what they look like or what they do.



来源:https://stackoverflow.com/questions/14667158/manage-iframes-form-submit-from-parent-frame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!