Finding the right document

K

Ken Kast

I have a frameset page with the following code snippets:

..
..
..
<script type="text/javascript">
<!--
var bannerFrame;
function load () {
var bannerDoc = bannerFrame.document;
alert(bannerFrame.name);
alert(bannerDoc.URL);
}
// -->
</script>
</head>
<frameset frameborder="0" rows="10%,*" onLoad="load();">
<frame id="banner" name="banner"
src="banner.htm" noresize="noresize" scrolling="no"
onLoad="bannerFrame=this;" />
..
..
..
When I run this the first alert message gives me the correct name. The
second alert gives me the url of the frameset page, not of the frame page.
Why is this, and how should I modify the script so that I can grab the
document for the frame?

Thanks.

Ken
 
G

Grant Wagner

Ken said:
I have a frameset page with the following code snippets:

.
.
.
<script type="text/javascript">
<!--
var bannerFrame;
function load () {
var bannerDoc = bannerFrame.document;
alert(bannerFrame.name);
alert(bannerDoc.URL);
}
// -->
</script>
</head>
<frameset frameborder="0" rows="10%,*" onLoad="load();">
<frame id="banner" name="banner"
src="banner.htm" noresize="noresize" scrolling="no"
onLoad="bannerFrame=this;" />
.
.
.
When I run this the first alert message gives me the correct name. The
second alert gives me the url of the frameset page, not of the frame page.
Why is this, and how should I modify the script so that I can grab the
document for the frame?

Thanks.

Ken

<script type="text/javascript">
function load () {
alert(window.frames['banner'].location.href);
}
</script>
</head>
<frameset frameborder="0" rows="10%,*" onload="load();">
<frame id="banner" name="banner"
src="about:blank" noresize="noresize" scrolling="no" />
</frameset>

Works in IE6SP1, Firefox 0.8, Opera 7.23. In Netscape 4 you get "access
disallowed from scripts at <uri> another domain." but that's probably only
because I'm using about:blank.

If you try it using your code (ie - setting bannerFrame=this), then it fails
in both Opera and Netscape 4 with "bannerFrame undefined".

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top