View Full Version : Open Link from Modal into Parent and Close Modal

04-03-2009, 12:25 AM
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 have got the code into my web page so that the modal window opens when a link is clicked. The modal window loads another page via an iframe. The page that opens in the modal window contains links. What I want to do is this: when the user clicks on a link in the modal window - load that linked page into the parent window and close the modal window. Is there a simple way to do this?

Thanks in advance for your help!

04-03-2009, 01:06 PM
A little more info --

The use of the modal window is for a web visitor to select their region and be taken to a specific homepage based on that selection.

Here is the code I have that opens the modal window:

<font size="-2"><b>Worldwide</b> [<a href="#" onClick="selectregion=dhtmlmodal.open('regionbox', 'iframe', 'region_select2.html', 'Select Your Region & Language', 'width=410px,height=300px,center=1,resize=0,scrolling=1'); return false">Change</a>]</font>

Here is the code for one of the links that I have in the page (region_select2.html) that opens in the modal window:

<a href="north_america.aspx" onClick="selectregion.close(); return false"><font size="-1">North America [English]</font></a>

Right now when I click on the link inside the modal window the new page (north_america.aspx) is loaded into the modal. I want to have it load in the parent (hidden behind the veil) and automatically close the modal.

I'm new to this forum so thanks again for reading through this. I'm hoping someone can help me sort this out.

04-04-2009, 08:16 AM
In general you can access the main parent window from inside the document of the modal window by using the JavaScript keyword "parent". So to load the link in question inside the main window while closing the modal window, you can try:

<a href="north_america.aspx" onClick="parent.selectregion.close(); parent.location=this.href; return false"><font size="-1">North America [English]</font></a>

04-07-2009, 02:57 PM
Thanks! I'll give that a try.