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

Q1758 How do I know which frame has the focus?

irt.org | Knowledge Base | JavaScript | Frame | Q1758 [ previous next ]

Q1758 How do I know which frame has the focus?

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


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


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