faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

109 of 173 people (63%) answered Yes
Recently 5 of 10 people (50%) answered Yes


How can I dynamically load a different url into a dialog window created from showModalDialog() in IE
When requesting a html page from the popup window which is opened by showModalDialog() , the page.lo
When requesting a html page from the popup window which is opened by showModalDialog() , the page.lo

Apr 6th, 2008 18:48
ha mo, Lee Anderson, Daniel LaLiberte, Alexander Yanovets, Mallik Murthy, brian white, Mike Kaderly, Arsen Yeremin, siva A,

RE: http://www.dotnetmonster.com/Uwe/Forum.aspx/asp-net-web-
There's a much easier solution to getting a modal dialog to appear in 
the same window. Simply name the window (i.e., window.name='asd';) and 
set the form target to the name of the window.
<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">
//Name the window. This allows the modal dialog to stay in the same 
window.name = "Foo";
<FORM ACTION="action_here" METHOD="method_here" NAME="name_here" 
That's much easier than iframes and meta tags so long as you are using 
a form to navigate (i.e., using submit) through the pages.
I take no credit for this - I found this at the above URL.
Lee Anderson
function showModalDialog() 
{ return window.open() // Not a true modal dialog
var obj_my_window = showModalDialog(); 
obj_my_window.location = "http://cnn.com";
The following is from the person who posed the original question:
I don't think I made myself clear.  IE has a method called 
showModalDialog() which opens a modal window.  Once opened I want to be 
able to click a button on the modal window and dynamically change the 
content of the entire document of that window.  I have tried:
window.location = "myURL.htm"
window.document.location.href = "myURL.htm"
All of these open a new, non-modal window.  I need the new url to be 
placed in the modal window.
Someone on another site suggested using frames and having the first 
frame be 0px in height and then directing the new content to the second 
frame, but I do not want to use frames.
From Brian - I don't think you can do this.  The window you open has 
only an html rendering dll loaded, I don't think it has the capability 
to navigate.  That's why it loads so incredibly fast.  BUT, what you 
can do is return the url you want to navigate to as a string as the 
returnvalue of the window.  Then in the calling code, where you have 
strVariable = window.showModalDialog(.. you can have as the next line a 
test of strVariable for some condition (http in the string maybe?), or 
you can just always then open another modal window with the value.  So 
you have strVariable = window.showModalDialog(.. and next line: 
strAnotherVariable = window.showModalDialog(strVariable, "", ....  The 
screen edge may flicker barely visibly, but very close to 
unnoticeable.  You can't sustain unlimited navigation very well, but if 
you need a couple levels it's fine.  Hmm, actually you could support 
unlimited navigation by putting it in a loop where the returnvalue 
isn't "" and isn't "break" or some other value you define for a 'quit 
this screen' button to return.  So you can effectively sidestep the 
lack of navigation by perpetually opening modal dialog windows that can 
only render html.
Addendum : 
I had the same problem, but I had a workaround which suited me just 
fine. The first url I load in the dialogwindow had the meta refresh tag 
which refreshes after a set amount of time. This DID load the new file 
in the same page...so there's navigation capability for you!  But not 
under user control.
here's the code I used:
<META HTTP-EQUIV="refresh" CONTENT="2;URL=Dummy.asp?dataIsland=<%
if it helps.
I have been successful using an iframe in the content of the dialog 
window that fills the window.  The url of the iframe would be the 
original url, and then your modal content can target itself with 
anchors, forms, etc.  Like this:
<body scroll="no">
<table cellpadding="0" cellspacing="0" border="0"
    width="100%" height="100%"
    style="table-layout: fixed"><tr><td valign="top">
  style="height:100%; width:100%">
  <A HREF="ModalContent2.html">Step 2</A>
  <A HREF="#" onclick="window.location.href=ModalContent3.html">Step 
    <input type=button value="Close"
           onclick="top.returnValue='whatever'; top.close()">
    <input type=submit>
In html that you initially load in modal dialog put <BASE 
target="_self"> in the HEAD section. Next reload will be in this modal