Spent a little time on this today and didn't see this issue specifically addressed anywhere, so I wanted to share:
To open a lightbox from a Flash movie you basically have to hit a javascript function that clicks an invisible lightbox link.
First, put this on your page somewhere:
<script type="text/javascript">
function openLightbox() {
fireEvent(document.getElementById("idOfYourLink"),'click');
}
function fireEvent(obj,evt){
var fireOnThis = obj;
if( document.createEvent ) {
var evObj = document.createEvent('MouseEvents');
evObj.initEvent( evt, true, false );
fireOnThis.dispatchEvent(evObj);
} else if( document.createEventObject ) {
fireOnThis.fireEvent('on'+evt);
}
}
</script>
Then create your HREF link to lightbox, like you normally would, although make it empty:
<a href="/path/to/pic/or/page" rel="lightframe[overlayWindowName|width:920px; height:540px; scrolling: no;]" id="idOfYourLink"></a>
Then call the following from your Flash button:
getURL("javascript:openLightbox();", "_self");
Put the empty link somewhere it won't get in the way - keep it close to the SCRIPT for ease-of-maintenance.
Advantages are that you don't have to code the link destination into the Flash movie, it's just a generic trigger.
Disadvantages are that this is a bit kludgy and you have have add new js, html and Flash code for each different flash button/lightbox. I'd be curious to know if there is a better way of doing this, but this is what I came up with after a couple hours of Googling.
Comments
Comment #1
stella CreditAttribution: stella commentedIf the id of the link is always going to be different, why not pass in the id of the link when calling openLightbox() ?
Comment #2
stella CreditAttribution: stella commentedAdded this to the Lightbox2 documentation at http://drupal.org/node/352573 Thanks!
Comment #4
zqproject CreditAttribution: zqproject commentedI tried to open a lightbox in javascript without manually clicking the lightbox link, but failed.
my browser (both firefox, IE6, and IE7) went to nowhere.
I used almost the same code mentioned here except in javascript directly. I cannot see the reasons. Anybody can help? Thanks a lot.
My code is listed below,