Open Joomla Modal With Javascript

Posted in Joomla!
2009-10-29 14:34:09 +0000 UTC

As part of a recent project, I needed to open a modal window using Javascript. Here's how I did it.

First, I made sure the modal behavior was loaded:


Then, in my Javascript, I created a new element to house all of my dynamic content (this could also be a hidden div, if needed). Once I had that, all I had to do was pass the MooTools reference of that object to SqueezeBox, and open.

var newElem = new Element( 'div' ).setText( 'demo' );
SqueezeBox.setContent( 'adopt', newElem );

Now, had I wanted to open an external resource with an iframe handler, I could use the following:

SqueezeBox.setContent( 'iframe', '' );