How to make IFRAME listen to click event of parent iframe and use the path of the clicked element in parent iframe?

You are doing a lot of looping and if-ing that jQuery will do for you automatically. Unless I am missing something. See my comments on each line.

You are doing a lot of looping and if-ing that jQuery will do for you automatically. Unless I am missing something. See my comments on each line: var iframes= parent.document.

GetElementsByTagName('iframe'); // why not use jQuery? For (var i= iframes. Length; i--;) { // why not use jQuery here?

Var iframe= iframesi; if($(iframe)) { // always true - even an empty jQuery object returns true // where does ahash come from? If (ahash. Path!

=undefined) { // Why not do this check outside the loop? $(iframe). Click(function(e) { $(this).

Find(ahash. Path). Trigger('click'); // this will do nothing // $(this).find() will be empty - your iframe has no children // you want $(this).contents().find(); }).click(); // why immediately call click and then unbind?

$(iframe). Unbind('click'); // why not just call the code? } // is this brace in the right spot?

// missing brace // missing brace I'd re-write it like this: $("iframe", parent. Document).contents(). Find(ahash.

Path).click(); Broken down, that is: $("iframe", parent. Document) // get all of the iframes in the parent document .contents() // get the content documents of those frames . Find(ahash.

Path) // find the elements matching the ahash. Path in each // of the frames' content documents .click(); // trigger a click on the matching elements in each frame Is that what you are trying to do? If so, then I believe your problem is that you are not calling .contents() on your iframe before calling .find().

Edit: Note that you cannot navigate to a url by calling $("a#myLink").click(). You'll have to manipulate location. Href instead.

However, in IE and newer versions of FireFox and Opera you can do so by calling the element's native DOM method .click() directly like this: $("a#myLink")0.click(). As this is part of HTML5, you'll probably be able to do so in Chrome shortly. Here's a demo showing the behavior of jQuery's click() method on links: http://jsfiddle.net/gilly3/C48mv/1.

Thanks gilly3 for the comments you added in my code. Yes I also felt I have done too much looping. In my code you have asked where does ahash come from?

Actually I am taking this from the click event $('a').click(). I have tried your code but I am not getting the result. You got me right, I am trying to do what you suggested, follow the path of the clicked element in the parent iframe and then trigger that path in the other iframe so that both iframes have the same content opened but don't know why this is not working.

– user850234 Sep 8 at 4:51 You have commented in one line "why call click immediately", this is because if I don't call click then the click event is not getting triggered. I made changes as you recomended by commenting but don't want to use location.href. I am using newer version of firefox.Is there some other alternative way of solving this by accessing the path of parent iframe element.

– user850234 Sep 8 at 6:01 I'm curious why you are opposed to using location.href. JQuery's click method will not navigate links - see this demo: jsfiddle.Net/gilly3/C48mv/1. To use the DOM method, try this: $("iframe", parent.

Document).contents(). Find(ahash. Path)0.click();.

One red flag I see in this code is it will trigger that link in all iframes, including the one that triggered the event. You could get stuck in an infinite loop. You should target just the iframe you want to manipulate.

– gilly3 Sep 8 at 15:51.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions