开发者

Accessing parent DOM/function from within an Iframe embedded in Windows 7 gadget

I have the following issue, Im creating a windows 7 gadget, which uses Iframe to load content.I have full control on the contents of the Iframe, what I want to do is, call a fun开发者_如何学Cction in the parent (windows 7 gadget html document), from within this Iframe, or even trigger a flyout from within the Iframe, when there is hover on a link or something.

Any help is greatly appreciated.

Thanks

Accessing parent DOM/function from within an Iframe embedded in Windows 7 gadget


Although Windows Desktop Gadgets were initially said to be excluded from the restrictions of the Same Origin Policy, that is only true of XMLHttpRequests. If the <iframe> is pointing to a page on the www, then any communication between the framed page and the hosting gadget will be blocked. If this is the case then you might be able to use the method of cross-domain communication that relies on changing the hash of the topmost window. From inside the frame, you would do something like this:

window.top.location.hash = "#ShowFlyout";

Then, in the code for the gadget you'd have something like this:

window.setInterval(function () {
    if (window.location.hash == "#ShowFlyout") {
        window.location.hash = "";

        System.Gadget.Flyout.file = "flyout.htm";
        System.Gadget.Flyout.show = true;
    }
}, 100);

I don't have my windows machine on hand to test it right now, but you could try it nonetheless.

If the iframe is pointing to a html document on the local machine, then you should be able to access the global System variable as a member of the topmost window object — which is the gadget — like this:

var System = window.top.System;
System.Gadget.Flyout.file = "some.htm";
System.Gadget.Flyout.show = true;

Or, also assuming you have control over the content of the flyout, you could set an event handler on all links with jQuery (since you tagged it):

$("a", iframe.contentWindow.document).click(function () {
    System.Gadget.Flyout.file = this.href;
    System.Gadget.Flyout.show = true;
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜