Same-domain jquery (cross) IFRAME operations dom

Source: Internet
Author: User
Tags php write

  This article is mainly on the same domain jquery (cross) IFRAME Operation Dom is introduced in detail, the need for friends can come to the reference, hope to help everyone else

Frame is still very popular, many places through it to achieve a special situation. For example, traditional upload, select under IE6, Proxy, Cross-domain and so on. Today, a brief description of the operation across the IFRAME, mainly using jquery to manipulate the DOM structure.   Code as follows: <iframe src= "a.php" id= "AA" ></iframe>  <iframe src= "b.php" id= "BB" ></iframe >  <input type= "button" id= "Read-aa" value= "read iframe #aa" >  <input type= "button" id= "Write-aa" Value= "Write iframe #aa" >   code as follows: $ (' #read-aa '). Click (function ()   {      var v=$ (' #aa '). Contents (). Find (' body '). HTML ();      alert (v); });  $ (' #write-aa '). Click (function ()   {        $ (' #aa ') contents (). Find (' div '). Append (' <hr> This is index.php operation aa.php write content '); });   The Main method is contents (), read the IFRAME.   2, iframe across the parent frame operation IFRAME   code is as follows: <! DOCTYPE html>  <meta charset= "Utf-8" >  <title>bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb< /title>  <script src= "Public/jquery.js" ></script>  <script>  $ (function ()   {      $ (' #read-parent-aa '). Click (function ()       {          var v=$ (' Body ', parent.document. Find (' #aa '). Contents (). Find (' body '). HTML ();          alert (v);     });      $ (' #write-parent-aa '). Click (function ()       {      &N Bsp   $ (' body ', parent.document). "Find (' #aa ')." Contents (). Find (' div '). Append (' <hr> This is the bb.php operation aa.php write content ');      }); });  </script>  <div>  This is the IFRAME #bb里的内容   </div>& nbsp <input type= "button" id= "Read-parent-aa" value= "Cross parent read iframe #aa" >  <input type= "button" id= " Write-parent-aa "Value=" cross-parent write iframe #aa ">   HTML: Code code as follows: <! DOCTYPE html> <meta charset= "Utf-8" > <title>jquery operation iframe</title> <script src= "http:// Ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js "></script> <iframe src=" a.php "id=" AA "> </iframe> <iframe src= "b.php" id= "BB" ></iframe> <input type= "button" id= "Read-aa" value= "read iframe #aa" > <input type= "button" id= "Write-aa" value= "write iframe #aa" > <script>  $ (function () { $ (' #read-aa ') . Click (function ()  {  var v=$ (' #aa '). Contents (). Find (' body '). html ();   alert (v);  });  $ (' #write-aa '). Click (function ()  {    $ (' #aa '). Contents (). Find (' div '). Append (' <hr> This is the index.php operation aa.php write content ');  }); }); </script>
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.