DelphiFAQ Home Search:
General :: Web publishing :: JavaScript :: Document


Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Force a page to always appear in a FRAMESET

Question:

Our site uses a horizontal frame at the top for navigation. So even if people visited my page through a direct link e.g. from the search engine Google, I want the page to appear in that frameset. How should I do this?

Answer:

You check to find out that a page is not framed and then you load the desired frameset:
if (top == window) top.location.href = 'frameset.html';

You can even pass the frame url in the query string e.g.
if (top == window) top.location.href =
'frameset.html?' + escape(window.location.href);


This line has to be in every to-be-framed document on your site.

Then in the main frame page - let's call it frameset.html - you read the query string to get the frame url and afterwards you document.write the frameset. The example below shows how such a Frameset.html file would look like.

// Frameset.html:
 
 <HTML>
 <HEAD>
 <SCRIPT>
 var url = location.search ?
   unescape(location.search.substring(1)) :
   'WelcomePage.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>

Generated 16:02:19 on Jul 20, 2017