Bootstrap: Modal: need ability to open modal from child iframe/window

Created on 23 May 2012  路  7Comments  路  Source: twbs/bootstrap

I have a page within an iframe with a button that when clicked opens a modal. What I want is for the backdrop and modal content to open up in the parent window, not within the iframe.

To test this out I've made some mods to the javascript so that instead of appending the backdrop to document.body, I append it to window.parent.document.body. I made the same change to $element in the show method. The backdrop successfully was added to the parent window but I couldn't get the modal content to do the same.

Any tips on how to do this cleanly?

js

Most helpful comment

+1 @ljharb

Have the modal live in the parent, then call window.parent.$("#modal").modal()

All 7 comments

Since the iframes must be on the same domain, my suggestion would be to have the modal content in the parent, and when something is clicked in the child, explicitly trigger "click" on a hidden opener in the parent. ie, do all the modal work in the parent, not in the child.

+1 @ljharb

Have the modal live in the parent, then call window.parent.$("#modal").modal()

Could you please ask questions like this in the mailing list? thanks! :)

quasipickle , your solution solve my problem. Thx!

Thanks ljharb and quasipickle. This solved the problem for me too. Now, I need to know how to avoid the iframe page jumping on the top when the modal popup opens...

thank you so much

How is this implemented?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bellwood picture bellwood  路  3Comments

kamov picture kamov  路  3Comments

devfrey picture devfrey  路  3Comments

MrCsabaToth picture MrCsabaToth  路  3Comments

knownasilya picture knownasilya  路  3Comments