conditional frameset

D

dan

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>
 
K

kaeli

Has anyone else done something like this before?

Conditional frames? No redirects?
Yup.
Didn't use client-side code, though. Or cookies. Servlets are my friend for
stuff like this. You can do this much easier with server-side code that
dynamically generates your html. Doesn't have to be servlets. Could be PHP,
ASP.net, perl, JSP, or whatever. Pass in params via the URL and have the page
generate as appropriate. Makes it easier for people to bookmark, too.

--
--
~kaeli~
The Bible contains six admonishments to homosexuals and
three hundred sixty-two admonishments to heterosexuals.
That doesn't mean that God doesn't love heterosexuals. It's
just that they need more supervision.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
B

bumbleguppy

Instead of writing the frames in the head, couldn't you use a NOSCRIPT
tag in the body for the non-frame page and just write the frames with
javascript in the script tag?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top