Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | DHTML | Q1293 [ previous next ]

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

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.