RE: Changing 2 iframes at once

Herr Christian Wolfgang Hujer wrote:

>> Is there a way to simultaneously change 2 iframes (or more)
>> with a single event (such as onClick)?
> 
> Depending on your layout perhaps you can change the 2 iframes
> to one iframe containing a page with a frameset with two frames
> or a body with two iframes to achieve your goal?

The best thing is of course not to use iframes at all. Instead,
one should use server side processing, like SSI, PHP or ASP to
include content into different areas of the page.

If the point is to load the content into an area without reloading
the page, one could do this with JavaScript. When done right, this
solution can work both with and without JavaScript or (special)
support for iframes and such. It might look like this:

<a href="mypage.php?action=changeArea&amp;areaId=23&amp;contentId=81"
  onclick="changeArea(23, 82); return false;">Change area content</a>

In this anchor, the href points to a PHP script that receives
arguments for changing area 23 with content 81. When clicked, the
onclick event will be fired in browsers with JavaScript support
and where it's not turned off.

In the onclick argument, the function changeArea() is called. This
function does the same thing as "mypage.php" does, but it doesn't
reload the page because it's all done on the client. The "return
false" statement makes sure that one doesn't gets returned to the
execution of the "href" when done executing the changeArea() script.

The details of what's being done inside "mypage.php" and changeArea()
is outside the scope of this mailing list imho, and is also not
very interesting. The main point is to offer functionality that don't
require too much from the client, which I think both JavaScript and
iframe do. Offering alternatives to iframe is hard, but to JavaScript
it's rather easy.

-- 
Asbjørn Ulsberg           -=|=-          X-No-Archive: No
"He's a loathsome offensive brute, yet I can't look away"

Received on Monday, 23 June 2003 02:41:35 UTC