Get the content of the iframe outside the iframeMethod 1Through the two APIs contentWindow and contentDocument: var iframe = document.getElementById("iframe1"); var iwindow = iframe.contentWindow; var idoc = iwindow.document; var idocument = iframe.contentDocument; console.log("window",iwindow); //Get the window object of iframe console.log("document",idoc); //Get the document of iframe console.log("html",idoc.documentElement);//Get the html of the iframe Among them, iframe.contentWindow can get the window object of iframe, and iframe.contentDocument can get the document object of iframe. Method 2Combined with the Name attribute, get it through the frames provided by the window: <iframe src ="/index.html" id="ifr1" name="ifr2" scrolling="yes"> <p>Your browser does not support iframes.</p> </iframe> <script type="text/javascript"> console.log(window.frames['ifr2'].window); console.dir(document.getElementById("iframe").contentWindow); </script> Get content outside the iframe within the iframe
Calling methods and variables defined in the parent page in the iframewindow.parent.window.parentMethod(); window.parent.window.parentValue; Methods and variables for operating iframe child pages in the parent pagewindow.frames["iframe_Name"].window.childMethod(); window.frames["iframe_Name"].window.childValue; SummarizeThere are two more points to note when using Iframe:
Determine if iframe loading is completeiframe.onload = function() { //TODO } Different domain communicationPassing data from parent page to child page Use the hash value of the location object to pass communication data through it. Add a data string after the src of the iframe in the parent page, and then get the data here instantly in some way in the child page. Subpage passes data to parent page A proxy iframe is used, which is embedded in the child page and must be in the same domain as the parent page. Then, the implementation principle of the same-domain communication method mentioned above is fully utilized to pass the data of the child page to the proxy iframe. Then, since the proxy iframe and the main page are in the same domain, the main page can obtain these data using the same domain method. This is the end of this article about how JS can operate on pages inside and outside the Iframe. For more relevant content about JS operating on Iframe pages, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Markup Languages - Lists Again
>>: Mysql modify stored procedure related permissions issue
Provide login and obtain user information data in...
HTML forms are commonly used to collect user info...
Types of joins 1. Inner join: The fields in the t...
This article example shares the specific code of ...
1. Optimization of commonly used HTML tags HTML s...
Table of contents Kill instruction execution prin...
Table of contents Preface Background data splicin...
Focus images are a way of presenting content that ...
Combining the various problems I encountered in m...
Note: In web development, after adding autocomplet...
We know that there are two ways to receive incomi...
The show processlist command is very useful. Some...
Table of contents 1. Introduction 1.1 Babel Trans...
Edit docker-compose.yml and add the following con...
HTML <div class="spinner"></di...