开发者

Jquery, trying to update div from colorbox to parent

Using colorbox again with iframe, Im trying to pass information from the colorbox back to th开发者_如何学Pythone parent window. All Im trying to do is update a div with new text passed via the colorbox after the color box is closed. I tried this in the colorbox popup:

JQuery(window.parent.document).find("#textdiv").html("Some updated text");
parent.jQuery.fn.colorbox.close();

Or

$(window.parent.document).find("#textdiv").html("Some updated text");
parent.jQuery.fn.colorbox.close();

Or

parent.JQuery("#textdiv").html("Some updated text");
parent.jQuery.fn.colorbox.close();

Or

parent.$("#textdiv").html("Some updated text");
parent.jQuery.fn.colorbox.close();

Then in the parent window I have:

<div id="textdiv"></div>

jQuery(".purchasepop").colorbox({width:"80%", height:"80%", iframe:true,
onClosed:function(){ alert($("#textdiv").html());return false; }});

But no matter what I try the alert box is blank. Any suggestions?


I played with this a bit and had similar difficulties. However, I identified a workaround. It's pretty easy to call a method in the parent page. So, in the parent have:

 function updateFunction(value) {
     $("#textdiv").html(value);
     $.colorbox.close(); // Or whatever - I don't know about colorbox
 }

and in the <iframe>, call

 parent.updateFunction("Some updated text");

This worked well for me. I believe the problem is the scope of the jQuery object. You have two of them (one in the parent, one in the iframe) and it can be annoying to grab them. I know there's a good way to do it, but I don't recall now.

Update: On a second attempt, parent.$("#textdiv").html("Some Updated Text"); worked just fine. So, my guess is that there is either something wrong with your callback order or parent has somehow gotten redefined or pointed elsewhere. Still, the above strategy might help with that, too.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜