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>

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.