Do Get Framed

Sometimes a particular web page only makes sense if it appears in a frame, yet users somehow find the page in an unframed state. This particularly tends to happen when users find the page through a search engine. To give the reader a clue that this isn't the page where they should be, paste this Javascript at the top of the page, before any text:

this code produces this
<SCRIPT TYPE="text/javascript">
<!--
function checkframed(gourl)
{
if (top == self)
document.write(
'<DIV STYLE="padding:8pt;' + 
'border-style:solid;border-width:8pt;' + 
'border-color:66CC33;">' + 
'<STRONG STYLE="font-size:30pt;' + 
'font-weight:900;font-family:sans-serif">' + 
'This page is intended as part of a ' + 
'<A HREF="' + gourl + '">framed document</A>.' + 
'</STRONG></DIV>');
}
checkframed("dgftop.html");
//-->
</SCRIPT>
this page

Change the URL in the last line to the URL of the frameset page. For example, if you want people to go to myhomepage.html then set the last line like this:

checkframed("myhomepage.html");

This script checks to see if the current page is the "top" page (if (top == self)). If it is, it writes out a notice to the user that they would probably rather be at another page, and writes out a link to that page.

You might notice a small disparity between this method and the Don't Get Framed method. In this example the user is presented with a passive link if they are not on the intended web page. In the previous example, however, no permission is asked: the browser is automatically forwarded to the intended page. The reason for this difference lies in the slight difference in intentions between the two pages. The "Don't Frame Me" script is intended to act as a deterrence, to stop somebody else from framing the page. The best deterrence in this case is to unload their page without further ado. The "Do Frame Me" script, however, is not intended to act as a deterrence, only as a gentle reminder, so a gentler method of redirection is used.





About the Author
Copyright 1997-2002 Idocs Inc. Content in this guide is offered freely to the public under the terms of the Open Content License and the Open Publication License. Contents may be redistributed or republished freely under these terms so long as credit to the original creator and contributors is maintained.