Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Navigating in a modal window

Status
Not open for further replies.

skippy2007uk

Programmer
Aug 10, 2007
18
GB
Hi,

I am opening up a new window via window.showModalDialog

In that window I am trying to navigate to a new URL, but rather than the location changing in the modal window, it is opening a new window instead.

I have set <base target="_self" /> which seems to solve some issues, but not this.

Any advice appreciated.
 
[0] The driving idea of showModalDialog is to have a synchronous channel of communication between the opener and the dialog. There should be some specific handshake between them. This handshake is implemented via the window.returnValue. And, the return value is at the same time captured by the opener. Whenever talk about returnValue, talk closing out of the dialog. Hence, I would say the recognized returnValue happens when the dialog is undergoing a managed-close.

[1] In your concrete case, you have to script in both the opener page and the dialog to prepare for this kind of managed close.

[1.1] Dialog

[1.1.1] Suppose your setTimeout is realized like this.
[tt]
setTimeout("window.location='xyz.htm'",1000);
[/tt]
[1.1.2]You should make it a managed close. Like this.
[tt]
setTimeout("x('xyz.htm')",1000);
[/tt]
with the handler x like this.
[tt]
function x(surl) {
window.returnValue=surl;
window.opener=self;
window.close();
}
[/tt]
[1.2] Opener

[1.2.1] When you open the dialog, suppose it is originally appearing like this.
[tt]
function y(surl) {
window.showModalDialog(surl);
//other lines...
}
[/tt]
(In this form, it is not using the modal dialog to its full, namely, the dialog nature is not exploited.)

[1.2.2] You should replace it by something like this.
[tt]
function y(surl) {
var sret=window.showModalDialog('abc.htm');
if ((typeof sret)!="undefined") {
y(sret); //relaunch the dialog with the new url
return false;
}
//other lines...
}
[/tt]
[2] The info pass back can be much more elaborated and the handshake accordingly. It is not limited to sret of type "undefined" to complete the dialog. The sret can be highly structure info and various followup action depend on it.
 
amendment
By this
>[self] var sret=window.showModalDialog('abc.htm');
I meant sure this.
[tt] var sret=window.showModalDialog([red]surl[/red]);[/tt]
 
Thanks for you reply, but I'm not sure you have understood my question.

I am asking whether it is possible to navigate to a different URL in a modal window without it spawning a new window.

Thanks.
 
That is not the purpose of the dialog.
 
So it's not possible then?

The modal dialog is launching an asp.net app, and postback events which navigate (via a respopnse.redirect) work fine. I am suprised that navigation via javascript (eg. windows.location.href) does not work.
 
It can and it is in the new windows. Redirect itself, you have to "ask for opinion" of its owner: the opener.
 
The point I'm trying to make is that navigation in the modal window alone works fine via asp.net postback events (response.redirect) - not via the opener/caller.

Navigation via a javascript function works, but opens a new window unlike the asp.net navigation.

Am I making myself clear?
 
You may keep your imagination to your own.
 
You ask me a question and I answer - unfortunately, you are not making much sense as you seem to missing the point of my original question.

I appreciate what you are trying to say, and the help you are providing though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top