faqts : Computers : Programming : Languages : JavaScript : Windows

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

69 of 79 people (87%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How can I ensure my page is always framed?
How can I ensure my page is always framed?

Mar 10th, 2000 07:12
Martin Honnen,


You check
  if (top == window)
to find out that a page is not framed and then you load the desired 
frameset.
  if (top == window)
    top.location.href = 'frameset.html';
If you want a dynamic frameset document where one frame can differ then 
pass the frame url in the query string e.g.
  if (top == window)
    top.location.href =
      'frameset.html?' + escape(window.location.href);
Then in frameset.html you read the query string to get the frame url
  var url = location.search ?
    unescape(location.search.substring(1)) :
      'someDefaultURLHere.html';
and afterwards you document.write the frameset:
  <HTML>
  <HEAD>
  <SCRIPT>
  var url = location.search ?
    unescape(location.search.substring(1)) :
      'someDefaultURLHere.html';
  var html = '';
  html += '<FRAMESET ROWS="150, *">';
  html += '<FRAME NAME="navBar" SRC="navBar.html">';
  html += '<FRAME NAME="content" SRC="' + url + '">';
  html += '<\/FRAMESET>';
  </SCRIPT>
  </HEAD>
  <SCRIPT>
  document.write(html);
  </SCRIPT>
  </HTML>