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

Q1758 How do I know which frame has the focus?

You are here: irt.org | FAQ | JavaScript | Frame | Q1758 [ previous next ]

Add a hidden variable on the frameset page, which updates when onFocus on the frame changes.

You can then access this variable from the frames using window.parent.document. The frameset:

<form name=framesetForm>
<input type=hidden id=activeFrame name=activeFrame value=1>
</form>

<frameset rows="200,*">
  <frame onfocus="framesetForm.activeFrame.value = 1" name="Frame1" src="Frame1.htm">
  <frame onfocus="framesetForm.activeFrame.value = 2" name="Frame2" src="Frame2.htm">
</frameset>

Inside the frames:

function CheckFrames() {
  var activeFrame;
  activeFrame = window.parent.document.framesetForm.activeFrame.value;
  if (activeFrame = 1) {
    alert('Frame 1 is active');
  } else {
    alert('Frame 2 is active');
  }
}

Submitted by Simon Renström

©2018 Martin Webb