开发者

how to invoke jquery-ui dialog which is in iframe from parent page

I am c开发者_Python百科reating a form using Jquery-ui. Buttons are in parent page and codes are in another page, which is embeded into parent page through iframe. can anyone tell me how can I invoke dialog function of Jquery-ui from parent page's button.

$( "#comment" ) 
.button()
 .click(function() 
{ parent.I1.f1(); });

//I1 is the frame id here is a button

<button id="comment" name="comment">Comment</button>

This is on the parent page.

In another page(Iframe page)

function f1(){
 $("#comment" ).dialog("open"); 
} 

is defined details and code of dialog box is here

jqueryui.com/demos/dialog/modal-form.html


Give your iframe an ID (eg myiframe), and then do something like this:

document.getElementById('myiframe').contentWindow.function();

Where function() is the function you want to execute.

Remember that the page in your iframe needs to be on the same domain as the parent page for this to work.


First, it will only work if the same domains are exactly the same, in other words, the iframe needs to belong to the same url, if not, a cross-browser exception will be thrown.

To call javascript methods on other frames, you can find thousands of articles out there for this, you simply read an existing answer

Invoking JavaScript code in an iframe from the parent page

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜