Home > Web Front-end > JS Tutorial > How JQuery operates the associated page of iframe

How JQuery operates the associated page of iframe

php中世界最好的语言
Release: 2018-04-26 15:47:15
Original
1496 people have browsed it

This time I will bring you JQueryHow to operate the associated page of iframe, what are the precautions for JQuery to operate the associated page of iframe, the following is a practical case, let's take a look.

JQUERY IFRAME
The following simply uses Jquery to operate some records of the iframe. This can be achieved using pure JS.

First, how to find the elements of the parent page in the iframe:

$('#id', window.parent.
document
)
Copy after login

Second, how to get the elements of the iframe in the parent page:

$(this).contents().find("#suggestBox")
Copy after login

Third, call the method and variable defined in the parent page in the iframe:

parent.method
parent.value
Copy after login

Use jquery to get the parent in the iframe Page body

iframe.html

<html>
<script src=&#39;jquerymin.js&#39;>
</script>
<body id=&#39;1&#39;>
    <p>it is a iframe</p>
</body>    
<script>
    $(document).ready(
        function()
        {
        var c = $(window.parent.document.body) //麻烦的方法: var c = $($(window).eq(0)[0].parent.document).find(&#39;body&#39;); ,忘了可以用前面的方法了
        alert(c.html());
        }
    );
</script>
</html>
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Calling the iframe page based on ID (with code)

How does jquery make iframe adaptive to the front-end height

The above is the detailed content of How JQuery operates the associated page of iframe. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template