Previously, a well know javascript was used that simply checked to see if the current page - the one that is a frame - was the top level page, while this provides a mechanism to identify a frame without the supporting pages, it was often resolved simply by redirecting to the correct frameset, which also meant that the page being looked at was lost and replaced with the default page of the frameset, the code is below and a demo is also available :
<script language="javascript">
if (document.location == top.location)
{
document.location="frameset.html";
}
</script>
Simply add the Javascript shown below into the page of your framset.
<script language="Javascript">
var frame_builder = 'index.html'
if (top.document == self.document)
{
if (confirm('This page is normally in a frameset. Do you wish to load it in context?'))
{
window.location = frame_builder +'?'+ window.location.pathname
}
}
</script>
<script language="Javascript">
var thatframe = 'somepage.html'
if (location.search)
{
var thatframe = (location.search.substring(1,location.search.length))
}
var frameset = '<FRAMESET ROWS="50%,50%">'+'<FRAMESET COLS="100%">'+'<FRAME NAME="thisframe" SRC="somepage.html" MARGINHEIGHT=0 MARGINWIDTH=0 SCROLLING=AUTO NORESIZE>'
+'<FRAMESET COLS="100%">'+'<FRAME NAME="thatframe" SRC= "'+ thatframe +'" MARGINHEIGHT=0 MARGINWIDTH=0 SCROLLING=AUTO NORESIZE>'
+'</FRAMESET>'
document.write(frameset)
</script>
If you want the redirect not to ask the user to confirm, then simply remove the following :
if (confirm('This page is normally in a frameset. Do you wish to load it in context?'))
{
window.location = frame_builder +'?'+ window.location.pathname
}