2

Possible Duplicate:
How to write this in jQuery “window.parent.document.getElementById('parentPrice').innerHTML”?

I have an app that I'm porting to the browser for demonstration purposes.

Basically I have a parent page with an iframe that houses the actual app. On the parent page I have some buttons to simulate device controls.

Basically I need some way for these parent page button clicks to be captured by the app running in the iframe.

I have tried creating global functions on the parent page to setup bindings, for example:

// parent document
var bindLeftArrow = function (callback) {
    $("div#controls button#left-arrow").on("click", function () {
        callback();
    });
};

// app initialization within iframe
parent.bindLeftArrow(function () {
    console.log("Left arrow pressed!");
    // do stuff
});

This didn't work, as "Left arrow pressed" never dumps out into my console. The other thing I was thinking I could do is something like:

// parent document
$("div#controls button#left-arrow").on("click", function () {
    $(document).trigger("LEFT_ARROW_PRESSED");
});

// app in iframe
$(<parent document selector>).bind("LEFT_ARROW_PRESSED", function () {
    console.log("Left arrow pressed!");
    // do stuff
});

Only I have no idea what I would put as the selector instead of "parent document selector".

Could anyone tell me how I would accomplish this?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Danny
  • 3,615
  • 6
  • 43
  • 58
  • I think this is what you're looking for: http://stackoverflow.com/questions/726816/how-to-write-this-in-jquery-window-parent-document-getelementbyidparentprice – Winfield Trail Sep 05 '12 at 02:12

0 Answers0