Mohammad Alipour Mohammad Alipour - 1 year ago 95
Javascript Question

How to check that a frame of frameset is exists

I have a frameset that has 3 frames:

<frameset rows="124, *, 0">
<frame id="f1" scrolling="No" frameborder="0" src="" name="control">
<frame id="f2" frameborder="0" src="" name="main">
<frame id="f3" noresize frameborder="0" name="go">

I'm going to check if frame with id = "f2" exist?

I have tried :

if( document.getElementById("f2").contentDocument.documentElement.innerHTML !== null) {

But not worked.
I know i should do something like:


but need more info

Answer Source

Well - actually what you should do is only check if document.getElementById("f2") return something, however in order for this to work you must set the doctype of your document to frameset:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "">

Otherwise the browser will not recognize the frame, and it will return nothing.

Check this fiddle:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download