• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

153
Views
Pasar variables jquery entre iframe y padre

¿Cómo puedo trabajar con jQuery e iframe ? Obtenga y pase var de iframe a body y de body a iframe . Tengo el siguiente ejemplo. ¿Cómo puedo hacer clic en el botón en iframe y hacer que tenga efecto en el #test del body ? ¿Qué tal ready var x en iframe?

 <body> var x = "whatever"; <div id"test"></div> <iframe width="200px" height="200px" src="page.html"></iframe> </body>

Dentro de page.html tengo

 <button>clickme</button> <script> var elm = $('<span>content</span>'); elm.appendTo('#test') </script>
about 3 years ago · Santiago Trujillo
3 answers
Answer question

0

$("#myid", top.document);

o

 $("#myid", parent.document.body);

Esto le dará acceso al contenedor del IFRAME

según: http://groups.google.com/group/jquery-en/browse_thread/thread/5997ef4a60a123af

about 3 years ago · Santiago Trujillo Report

0

Desde la perspectiva de los padres:

 var iFrameValue = $('#iframe').get(0).contentWindow.myLocalFunction();

O

 var iFrameValue = $('#iframe').get(0).contentWindow.myLocalVariable;

Desde la perspectiva del iframe

 <script type="text/javascript"> var myLocalVariable = "hello"; function myLocalFunction () { return "hello"; } </script>
about 3 years ago · Santiago Trujillo Report

0

Puede usar las propiedades contentWindow y contentDocument , si la misma política de origen no es un problema. He configurado una demostración . Ver código para la demostración y código para iframe .

about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error