manage iframe's form submit from parent frame?

2019-06-14 02:21发布

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>

2条回答
男人必须洒脱
2楼-- · 2019-06-14 02:44

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>
查看更多
The star\"
3楼-- · 2019-06-14 02:58

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.

查看更多
登录 后发表回答