How To Make Iframe Listen To Click Event Of Parent Iframe And Use The Path Of The Clicked Element In Parent Iframe February 26, 2024 Post a Comment I have two iframes in my html page in the same domain Solution 1: 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= iframes[i]; 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 braceCopyI'd re-write it like this:$("iframe", parent.document).contents().find(ahash.path).click(); CopyBroken 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 frameCopyIs 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/ Share Post a Comment for "How To Make Iframe Listen To Click Event Of Parent Iframe And Use The Path Of The Clicked Element In Parent Iframe"
Post a Comment for "How To Make Iframe Listen To Click Event Of Parent Iframe And Use The Path Of The Clicked Element In Parent Iframe"