View Full Version : Modal onload event?

11-25-2009, 10:05 PM
1) Script Title: DHTML Modal window v1.1

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/dhtmlmodal.htm

3) Describe problem: I know the Modal window has an event handler that fires when the Modal is closed, but how would I execute some code when the Modal is first created? I use the ajax version of the modal and have tried using the onload event in the <body> of my external content, but this doesn't work. Any suggestions? Thanks.

11-26-2009, 05:09 AM
Are you simply opening one modal window on your page/ site, in which the onload code is the same throughout? If so, the easiest way to execute some code when the script has completed fetching the Ajax page is to directly modify dhtmlwindow.js and insert your code in the following chunk below:

ajax_loadpage:function(page_request, t){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){

11-27-2009, 09:44 PM
Actually, I use the modal numerous times and need to vary the onload code throughout the site. Maybe I could add an argument to the ajax_loadpage() function and this value could be used in a switch statement to get the custom code? Any other suggestions?

Thanks for your help.

11-28-2009, 07:32 PM
Sure, try the below modified dhtmlwindow.js file. It adds support for a new event handler called onajaxpageload. Here's a sample usage:

ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", "windowfiles/external.htm", "#3: Ajax Win Title", "width=450px,height=300px,left=300px,top=100px,resize=1,scrolling=1")
ajaxwin.onclose=function(){return window.confirm("Close window 3?")} //Run custom code when window is about to be closed

In the above case, a alert will be shown when the ajax page within the DHTML window has finished loading.

11-29-2009, 07:21 PM
Wow! This is perfect. Thanks so much.