Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1293 How can I dynamically change the src of a layer from within a layer?

You are here: irt.org | FAQ | DHTML | Q1293 [ previous next ]

The following works - but then crashes my browser (Netscape Navigator 4.7 on Linux):

test.htm:

<html>

<head>

<script language="JavaScript"><!--
function load_into_layer(name,href) {
    if (document.layers) {
        setTimeout('window.document.layers["' + name + '"].src = "' + href + '"',1000);
    }
}
//--></script>

</head>

<body onLoad="load_into_layer('myLayer','test1.htm')">

<h1>test.htm</h1>

<span name="myLayer" style="position:absolute; width:100; height:100;"></span>

</body>

</html>

test1.htm:

<html>

<body>

<h1>test1.htm</h1>

<p>
<a href="javascript:window.load_into_layer('myLayer','test2.htm')">test2.htm</a>
</p>

</body>

</html>

test2.htm:

<html>

<body>

<h1>test2.htm</h1>

</body>

</html>

If you change test1.htm to the following, then the only one that works is the form button, the remainder, except the body tag's onLoad event handler cause the browser to crash. The onLoad event handler seems to continually loop.

<html>

<body onLoad="window.document.layers['myLayer'].load('test2.htm',0)">

<h1>test1.htm</h1>

<p>
<a href="javascript:window.load_into_layer('myLayer','test2.htm')">test2.htm</a>
<br>
<a href="javascript:' '" onClick="window.load_into_layer('myLayer','test2.htm');return false">test2.htm</a>
<br>
<a href="javascript:' '" onClick="window.document.layers['myLayer'].load('test2.htm',0);return false">test2.htm</a>
<br>
<a href="test2.htm">test2.htm</a>
</p>

<form>
<input type="button" value="test2.htm" onClick="window.document.layers['myLayer'].load('test2.htm',0)">
</form>

</body>

</html>

©2018 Martin Webb