call a function in parent document from a link in iframe

  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Posts: 854

Post 3+ Months Ago

I have an iframe (yeah yeah, don't use an iframe...I know). I want to call a function that's written in the parent of the iframe when a user clicks a link inside the iframe. the age within the iframe is on my domain, so if that was a foreseen problem it's nothing to worry about. I'm just not even sure what to look for on google. Any ideas?
  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Posts: 162
  • Loc: India-Kolkata

Post 3+ Months Ago

I don't think iframe will work?! I have no idea on that.
Also how can you call a function?! you may call a page(containing that function) at most, that too by using frames.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

If he is talking about javascript, then you could call a function via onclick... if it's PHP, you could initiate the function bby a GET trigger...

At the iFrame link you could set '?dofunction=true' and at the main page, if ?dofunction is set and if ?dofunction equals true, then the function would be initiated.

I think there is a way to target something outside of the iFrame... I'm not sure though...
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Posts: 854

Post 3+ Months Ago

sorry, my bad...I'm talking about javascript with jquery.

In order to call the page containing the iframe - when clicking a link inside the iframe - you use
Code: [ Select ]
window.parent


I have a function called "contentLoad" inside my parent document.
Code: [ Select ]
 
function contentLoad()
{
        $(document).ready(function()
        {
            $("#contentWrap").slideToggle("slow");
            setTimeout(function()
                {
                    $("#contentWrap").slideToggle(1200);
                }, 1500);
        });
}
 
  1.  
  2. function contentLoad()
  3. {
  4.         $(document).ready(function()
  5.         {
  6.             $("#contentWrap").slideToggle("slow");
  7.             setTimeout(function()
  8.                 {
  9.                     $("#contentWrap").slideToggle(1200);
  10.                 }, 1500);
  11.         });
  12. }
  13.  


"#contentwrap" is a div that wraps around the iframe.

I want "contentLoad()" to run whenever a user clicks on a link within the iframe.

I added a piece of code inside the iframe page that looks like this:
Code: [ Select ]
$(document).ready(function()
{
    $("a").click(function(event)
    {
        window.parent.contentLoad();
    });
});
  1. $(document).ready(function()
  2. {
  3.     $("a").click(function(event)
  4.     {
  5.         window.parent.contentLoad();
  6.     });
  7. });

This isn't working. Any ideas why?
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Posts: 854

Post 3+ Months Ago

okay, screw all of that. Changed my mind on the approach to make it easier.

New code in the iframe:
Code: [ Select ]
$("a").click(function()
{
        window.parent.$("#contentWrap").toggle('normal');
        setTimeout(function()
    {
        $("#contentWrap").slideToggle(1200);
    }, 500);
});
  1. $("a").click(function()
  2. {
  3.         window.parent.$("#contentWrap").toggle('normal');
  4.         setTimeout(function()
  5.     {
  6.         $("#contentWrap").slideToggle(1200);
  7.     }, 500);
  8. });


In the parent window of the iframe there is a div with the id "contentWrap"

I want this div to shrink to nothing, wait half a second, and then grow back to its original size.
I want this "toggle" to take place whenever a user clicks on a link within my iframe. Why isn't this working?
  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Posts: 162
  • Loc: India-Kolkata

Post 3+ Months Ago

The <iframe> tag does not support any event attributes.
http://www.w3schools.com/TAGS/tag_iframe.asp

also window.parent can be called only with frames not iframes.

You should think of using frames instead!
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Posts: 854

Post 3+ Months Ago

I'm not attempting to call an event on a frame or an iframe. I'm trying to call an event for a link within the page that will be displayed within the iframe. I want to call a function whenever the user clicks on a link within the document held in the iframe, that function needs to affect the elements in the parent document.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

I think dark_lord is talking about calling an even from an iframe...

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 42 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.