Hello -
I'm working on a page that will deliver a frameset under certain
conditions and delivers a normal page under other conditions. I would
like to avoid using a redirect so that the URL doesn't change.
I have code that works on most browsers (Mac IE and Safari don't like
it, but that may OK). How it works is that the Javascript writes out a
frameset at the top of a page, before the browser gets to the body tag.
This generates the frames and prevents the body portion of the page
from rendering.
The code checks to see that there isn't a "turn off frames" cookie and
that the page isn't already in a frame. If so, it writes the frameset
tags, including a frame src pointing to itself. IE doesn't seem to like
this, so there's a redundant line of code that loads the page into that
frame again.
Below the javascript code is the rest of a standard HTML body. So, if
the framesets aren't created, and the unframed page appears normally.
I've ommitted standard cookie-grabbing code for the sake of brevity.
The cookie value is stored in the killFrame var.
Has anyone else done something like this before? This feels like a bit
of a hack, but it may be the best way (as long as I deliver it only to
browsers that can pull it off)..
begin code snippet:
________________________
-script tag here-
// ( cookie-grabbing code goes here, puts value into killFrame )
var thisPage = self.document.location.href;
if ((self == top) && (killFrame != "1")) {
document.open();
document.write('<frameset rows="*,110" frameborder="NO" border="0"
framespacing="0">');
document.write('<frame src="' + self.document.location.href + '"
name="mainFrame" target="_top">');
document.write('<frame src="adframe.htm" name="adFrame" scrolling="NO"
noresize target="_top"></frameset>');
document.close();
//for IE
top.frames[0].location.href = thisPage;
}
// removes frame and drops cookie when user clicks "close frame button"
function closeFrame() {
days = .5;
var expdate = new Date();
expdate.setTime(expdate.getTime() + days*24*60*60*1000);
document.cookie = "LATadframe=1; expires=" + expdate.toGMTString();
top.location.href = document.location.href;
}
-end script tag here -
</HEAD>
<BODY>
body of page still goes here.
</body>
</html>
---------------
end code