hey guys! onload function is working in window.open! but it is not working in .showmodaldialog

newwindow2=window.open('app.html','app','Width:700;Height:350; modal:true;');
 newwindow2.onload=function()
	{           alert("hello");
         }
This works 

newwindow2=window.showModalDialog('app.html','app','dialogWidth:700px;dialogHeight:350px;dialogTop:200px; dialogLeft:200px;resizable=no;');
newwindow2.onload=function()
	{           alert("hello");
         }
Not working

Recommended Answers

All 5 Replies

Yo, window.showModalDialog is new to me.

I would put the onload handler in the page(s) that appear in the popup; app.html and any others.

If the onload handlers are complex or need access to data in the main window, then get the popup's onload handler to call function(s) in the parent window; eg.

//in app.html
onload = function(){
    parent.popupOnload();
};

I've never tried this but you should be able to use the little used .call; method.

//in app.html
onload = function(){
    parent.popupOnload.call(self);
};

Then in the parent window's popupOnload function, you can, if necessary, use this to refer to the popup window.

//in parent window
var myVar = 'sample data in the parent window';
function popupOnload(){//note, no argument here.
    var element1 = this.getElementById('myElement1');
    element1.onclick = function(){
        ...
        //here the popup is given access to variables (within scope) in the parent window.
        alert(myVar);
        ...
    }
}

That would be advantageous if the parent window needs to be in control of the popup's behaviour, whilst making popupOnload independent of the name you give to the reference returned by window.open or window.showModalDialog ( window2 in your examples), and therefore more amenable to reuse (eg if you had two or more popups with similar functionality).

Airshow

thanks for your reply.. airshow.. is there a way can i make the parent modal after the popup in window.open??

Yo,

thanks for your reply.. airshow.. is there a way can i make the parent modal after the popup in window.open??

Not as far as I'm aware but you could always adopt the "lightbox" approach, in which a dialog is opened in the same (parent) window, whilst everything else is greyed out ... effectively a modal dialog without opening another operating-system window.

Because the dialog is in the same window, it enjoys the same javascript scopes(s) as other elements on the page, making reliable coding much simpler.

Lightboxes seem to be the method of choice these days. I'm not an expert, so Google "lightbox" for examples, code and discussion.

Airshow

hey guys! onload function is working in window.open! but it is not working in .showmodaldialog

newwindow2=window.open('app.html','app','Width:700;Height:350; modal:true;');
 newwindow2.onload=function()
	{           alert("hello");
         }
This works 

newwindow2=window.showModalDialog('app.html','app','dialogWidth:700px;dialogHeight:350px;dialogTop:200px; dialogLeft:200px;resizable=no;');
newwindow2.onload=function()
	{           alert("hello");
         }
Not working

dialog box is in fact the same as msg box - if you can make your msg box alert you some other msg - same would be true for the dialog box, but yu can't!

Instead of alerting from an "alert" try changing something else to make sure if it does trigger the onload evend at all or not. [although it shouldn't]. If it doesn't, than try putting the onload fonction in the dialog code. This might work. [eventhough dialogs aren't windows, and the onload event is a member of window object. But since modal and modeless dialogs aren't standard features of borowsers, there might be a slight chance that one of my proposals might work.

thanks for your sugession Troy .. I see to this now :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.