Can't create a handle to an iframe.

D

Daz

Hi everyone.

I am trying to create a handle to an iframe, but the script only gets
to a certain point and then fails. I am new to JavaScript, and I have
tried everything I can think of, but I just can't seem to figure it
out.

Below is the script with some comments so you can see what's happening.

var tmp_id = document.getElementById("BROWSER");
// tmp_id = [object HTMLIFrameElement]

var f_browser = tmp_id.contentDocument;
// f_browser = [object HTMLDocument]

f_browser = f_browser.contentWindow.document;
// f_browser = undefined

Could anyone explain what I am doing wrong. I have used this method
after seeing several examples online, although to be honest, I don't
understand what it's doing (or not doing) 100%.

Any help would be appreciated.
 
M

Martin Honnen

Daz said:
I am trying to create a handle to an iframe, but the script only gets
to a certain point and then fails. I am new to JavaScript, and I have
tried everything I can think of, but I just can't seem to figure it
out.

Use e.g.
<iframe name="iframeName" src="whatever.html" ...></iframe>
in your HTML markup then from the document containing that iframe you
can script e.g.
var iframe = window.frames.iframeName;
or
var iframe = window.frames['iframeName'];
then (if you still want to care about Netscape 4 which does not support
iframes) you check e.g.
if (iframe) {
// now decide what you want to use,
// iframe is the iframe window object
// iframe.document the document in the iframe
}
 
D

Daz

Martin said:
Daz said:
I am trying to create a handle to an iframe, but the script only gets
to a certain point and then fails. I am new to JavaScript, and I have
tried everything I can think of, but I just can't seem to figure it
out.

Use e.g.
<iframe name="iframeName" src="whatever.html" ...></iframe>
in your HTML markup then from the document containing that iframe you
can script e.g.
var iframe = window.frames.iframeName;
or
var iframe = window.frames['iframeName'];
then (if you still want to care about Netscape 4 which does not support
iframes) you check e.g.
if (iframe) {
// now decide what you want to use,
// iframe is the iframe window object
// iframe.document the document in the iframe
}

Martin,

Many thanks. You made everything sound so much simpler than I was
actually making it. Your method works great, and has saved me a lot
more head scratching and yelling abusive obscenities at my computer
monitor.

All the best.

Daz.
 
D

Daz

Daz said:
Hi everyone.

I am trying to create a handle to an iframe, but the script only gets
to a certain point and then fails. I am new to JavaScript, and I have
tried everything I can think of, but I just can't seem to figure it
out.

Below is the script with some comments so you can see what's happening.

var tmp_id = document.getElementById("BROWSER");
// tmp_id = [object HTMLIFrameElement]

var f_browser = tmp_id.contentDocument;
// f_browser = [object HTMLDocument]

f_browser = f_browser.contentWindow.document;
// f_browser = undefined

Could anyone explain what I am doing wrong. I have used this method
after seeing several examples online, although to be honest, I don't
understand what it's doing (or not doing) 100%.

Any help would be appreciated.

Hi. I have one more problem. The browser doesn't apear to stop loading
the page. Is there any way I can close the open handle, on the code
above?
 
D

Daz

Daz said:
Daz said:
Hi everyone.

I am trying to create a handle to an iframe, but the script only gets
to a certain point and then fails. I am new to JavaScript, and I have
tried everything I can think of, but I just can't seem to figure it
out.

Below is the script with some comments so you can see what's happening.

var tmp_id = document.getElementById("BROWSER");
// tmp_id = [object HTMLIFrameElement]

var f_browser = tmp_id.contentDocument;
// f_browser = [object HTMLDocument]

f_browser = f_browser.contentWindow.document;
// f_browser = undefined

Could anyone explain what I am doing wrong. I have used this method
after seeing several examples online, although to be honest, I don't
understand what it's doing (or not doing) 100%.

Any help would be appreciated.

Hi. I have one more problem. The browser doesn't apear to stop loading
the page. Is there any way I can close the open handle, on the code
above?

f_browser.document.close();

Sorted! :)
 

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
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top