Forum Moderators: open

Message Too Old, No Replies

Using 2 iframe buffers on the same page

         

lucesei

6:07 pm on Mar 5, 2004 (gmt 0)

10+ Year Member



Hi, I'm not so good at combining scripts. I am using the following code for an iframe buffer on my page, to display an external page ---call it file01.html--:


<head>
<script type="text/javascript">
function loadExternal(url) {
if ( window.frames['buffer'] ) {
window.frames['buffer'].location = url;
var lyr = document.getElementById? document.getElementById('display'): document.all? document.all['display']: null;
if ( lyr && typeof lyr.innerHTML!= "undefined" ) {
lyr.innerHTML = '<img src="/images/common/loading.gif" alt="">';
}
return false;
}
return true; // other browsers follow link
}

// called when documents loaded into iframe (from their body's onload attribute)
function displayExternal() {
var lyr = document.getElementById? document.getElementById('display'): document.all? document.all['display']: null;
if ( window.frames['buffer'] && lyr && typeof lyr.innerHTML!= "undefined" ) {
lyr.innerHTML = window.frames['buffer'].document.body.innerHTML;
}
}

</script>
</head>

<body onload="loadExternal('file01.html')">

<div id="display"></div>

<!-- image placed here for preload (used in loadExternal function) -->
<iframe id="buffer" name="buffer" src="/images/common/loading.gif">Sorry, your browser does not support iframes.</iframe>
</body>

Now I have the need to use another iframe buffer on the same page, to display a second external page ---call it file02.html---.

Question: which is the most efficient way to do the job?

Thanks a lot for all the help you'll be able to give me.

isitreal

3:58 pm on Mar 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just add another parameter to the initial function:

function loadExternal(url, iframe_id) {

then change this:
var lyr = document.getElementById? document.getElementById('display'): document.all? document.all['display']: null;

to this:
var lyr = document.getElementById? document.getElementById(iframe_id): document.all? document.all[iframe_id]: null;

and this:

function displayExternal() {
var lyr = document.getElementById? document.getElementById('display'): document.all? document.all['display']: null;

to this:

function displayExternal(iframe_id) {
var lyr = document.getElementById? document.getElementById(iframe_id): document.all? document.all[iframe_id]: null;

and just put in the right iframe id on the function call