PDA

View Full Version : DHTML Window widget - Open a window from an iframe



billgates2000
11-01-2007, 09:38 AM
1) Script Title:
DHTML Window widget

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

3) Describe problem:

Is there a way to have a window (using an iframe), that will contain a hyperlink which opens another window on the main page?

An example of what I'm trying to do can be found here:

http://www.eikones.com/test/test.html

If you open Window2, you'll see a link to open Window1. Is there a way to make this link open window1 on the main page?

thanks,
n.

ddadmin
11-02-2007, 05:51 AM
Sure, for a IFRAME based DHTML window, the way to reference anything on the main page is just to use the "parent." keyword, for example:


<a href="javascript:parent.openwindow1()">sdffdfd</a>

The above link is assumed to be inside Window 2, and "openwindow1()" is a function on the main page that opens Window 1.

billgates2000
11-02-2007, 06:42 AM
Hi again,

I'm not very familliar with javascript, so I think I need some more help.

I tried using the code above, but IE gives me an "object doesn't support this property or method" error when the link is clicked. Doesn't seem to work in firefox either.

You can see my test pages on: http://www.eikones.com/test/test.html

Basically, on the main window, the code that opens window1 is:

<a href="#" onClick="ajaxwin=dhtmlwindow.open('window1', 'iframe', 'window1.html', 'window1', 'width=650px,height=200px,left=300px,top=100px,center=1,resize=0,scrolling=1'); return false">open window 1</a>

So what I need to do it to put a link in the external page that loads in the iframe of window2 (i.e. window2.html), that will trigger the same action on the main page.

Please note that, on the main page, window1 does not show up using a function. There will be too much data in there, so we only want it to show up when the user wants (so there is just javascript code in the hyperlink of the main page, no javascript functions).

thanks,
n.

ddadmin
11-02-2007, 07:04 AM
First, make sure on your main page, that the variable you assign each DHTML window is unique:


<a href="#" onClick="ajaxwin=dhtmlwindow.open('window1', 'iframe', 'window1.html', 'window1', 'width=650px,height=200px,left=300px,top=100px,center=1,resize=0,scrolling=1'); return false">open window 1</a>

<br /><br />

<a href="#" onClick="ajaxwin2=dhtmlwindow.open('window2', 'iframe', 'window2.html', 'window2', 'width=250px,height=400px,left=300px,top=100px,center=1,resize=0,scrolling=1'); return false">open window 2</a>

I've given the second window a "ajaxwin2" name to make it unique. Secondly, to make it easier to call window1 from window 2, encase the code for window1 in a function instead, so you end up on your main page with this instead:


<script type="text/javascript">

function openwindow1(){
ajaxwin=dhtmlwindow.open('window1', 'iframe', 'window1.html', 'window1', 'width=650px,height=200px,left=300px,top=100px,center=1,resize=0,scrolling=1')
}

</script>

<a href="#" onClick="openwindow1(); return false">open window 1</a>

<br /><br />

<a href="#" onClick="ajaxwin=dhtmlwindow.open('window2', 'iframe', 'window2.html', 'window2', 'width=250px,height=400px,left=300px,top=100px,center=1,resize=0,scrolling=1'); return false">open window 2</a>

Then, on the Iframe page within window2, your link to call window1 would look like:


<a href="javascript:parent.openwindow1()">Open window 1</a>