return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>jquery - Calling Parent Page JavaScript Function In An Iframe - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Calling Parent Page JavaScript Function In An Iframe - Stack Overflow

programmeradmin1浏览0评论

I am using an iFrame in my application. Let me give an example here. I have main page as

<html>
  <head>
    <script src='jquery.js'></script>
    <script>
      function TestFunction()
      {
        var FirstName = $("#first_name").val();
        alert(FirstName);
      }
    </script>
  <head>
  <body>
    Enter First Name: <input type='text' size='20' id='first_name'><br />
    <input type='button' value='Cilck' onclick='TestFunction();'><br />
    <iframe id='test_iframe' src='test_iframe.htm' height='200' width='200'>
    </iframe>
  </body>
</html>

...and this works fine with alerting whatever is entered in textbox

But is it possible to invoke the same function in iframe that will alert the value present in textbox of the parent page?

Suppose test_iframe.htm code is like this

<html>
  <head>
  <script src='jquery.js'></script>
  <script>
     function IframeFunction()
     {
        TestFunction(); // I know this wont work.. just an example
     }
  </script>
  <head>
  <body>
    <input type='button' value='Click' onclick='IframeFunction();'>
  </body>
</html>

Can this be done ?

I am using an iFrame in my application. Let me give an example here. I have main page as

<html>
  <head>
    <script src='jquery.js'></script>
    <script>
      function TestFunction()
      {
        var FirstName = $("#first_name").val();
        alert(FirstName);
      }
    </script>
  <head>
  <body>
    Enter First Name: <input type='text' size='20' id='first_name'><br />
    <input type='button' value='Cilck' onclick='TestFunction();'><br />
    <iframe id='test_iframe' src='test_iframe.htm' height='200' width='200'>
    </iframe>
  </body>
</html>

...and this works fine with alerting whatever is entered in textbox

But is it possible to invoke the same function in iframe that will alert the value present in textbox of the parent page?

Suppose test_iframe.htm code is like this

<html>
  <head>
  <script src='jquery.js'></script>
  <script>
     function IframeFunction()
     {
        TestFunction(); // I know this wont work.. just an example
     }
  </script>
  <head>
  <body>
    <input type='button' value='Click' onclick='IframeFunction();'>
  </body>
</html>

Can this be done ?

Share Improve this question asked Apr 19, 2012 at 11:33 skosskos 4,2428 gold badges38 silver badges59 bronze badges 1
  • possible duplicate of Iframe Function Calling From Iframe to parent page javascript function – Jan Hančič Commented Apr 19, 2012 at 11:38
Add a ment  | 

3 Answers 3

Reset to default 4

I believe this can be done with 'parent'

function IframeFunction() 
{ 
   parent.TestFunction(); 
}
<html>
  <head>
  <script src='jquery.js'></script>
  <script>
     function IframeFunction()
     {
       parent.TestFunction();  // or top.TestFunction()
     }
  </script>
  <head>
  <body>
    <input type='button' value='Click' onclick='IframeFunction();'>
  </body>
</html>
<a onclick="parent.abc();" href="#" >Call Me </a>

See Window.Parent

Returns a reference to the parent of the current window or subframe.

If a window does not have a parent, its parent property is a reference to itself.

When a window is loaded in an , , or , its parent is the window with the element embedding the window.

This answer is taken from stackoverflow

发布评论

评论列表(0)

  1. 暂无评论