JQuery operation iframe parent page and child page elements and methods of of instance

  • 2020-03-29 23:54:29
  • OfStack

JQUERY IFRAME
The following is a simple use of Jquery to manipulate some of the iframe records, which can be implemented using pure JS and.

First, how to find a parent page element in an iframe:
$(' # id 'window. The parent. The document)

Second, get the element method in the iframe in the parent page:
$(this). The contents (.), find (" # suggestBox ")

Third, invoke the methods and variables defined in the parent page in the iframe:
The parent. The method
The parent. The value

Iframe USES jquery to get the body of the parent page

The iframe. HTML


<html>
<script src='jquerymin.js'>
</script>
<body id='1'>
    <div>it is a iframe</div>
</body>    
<script>
    $(document).ready(
        function()
        {

        var c = $(window.parent.document.body) //The method of trouble: var c = $($(window). Eq. (0) [0] parent. The document), find (" body "); I forgot to use the previous method

        alert(c.html());
        }
    );

</script>
</html> 


Related articles: