Specifying frame behaviour

How can I force a page, designed to appear in a frame, to always appear in that frame even when the URL is called directly from a browser.
LVL 1
mnewnhamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mayhewCommented:
I would use javascript to detect if the page is in a frame.

If it's not, I would redirect the browser to the url that includes the framed version of the page.

Let me know if you need more details.
0
mblaseCommented:
Here's some code that should do the trick. Modify and suit to your own purposes:

==================
frameset.html
==================

<frameset rows="150,*">
      <frame name="nav" src="navigation.html">
      <frame name="body" src="mainbody.html">
</frameset>

==================
navigation.html
==================

<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
var framer = "frameset.html";
var thisframe = "nav";
if (parent.frames.thisframe.location != document.location)
  parent.location = framer;
//-->
</SCRIPT>
</HEAD>
<BODY>

navigation is here

</BODY>
</HTML>


==================
mainbody.html
==================

<HTML>
<HEAD>
<TITLE></TITLE>

<SCRIPT LANGUAGE="JavaScript">
<!--
var framer = "frameset.html";
var thisframe = "body";
if (parent.frames.thisframe.location != document.location)
  parent.location = framer;
//-->
</SCRIPT>


</HEAD>
<BODY>

main body is here

</BODY>
</HTML>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mayhewCommented:
Hi mblase,

It's considered bad taste in this forum to post somebody else's comment as an answer.

The fact that you supplied code is irrelevent.

Please be more considerate.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

egbservicesCommented:
Hi mayhew and the others
I am a learner too and always apprechiated the answers which have some code which I can cut, paste & modify. By just telling "I would use javascript to detect if the page is in a frame..." is really no more than pointing mnewnham in a direction he is probably well aware of already... If you feel bad about that mblase beat you with an answer... then do it the same way next time. After all you have answered many questions in the past so you should know that this can and will always happen.

Edi

Try this too mnewnham... it starts my frame page always as a frame even when you enter the menu or logo frame url 1st.  


<html>
<head>
   
<title>Your page title</title>

<SCRIPT LANGUAGE="JavaScript">

<!--Hide script from old browsers
 if (top.location == self.location){
                 top.location.href = "index.htm"
                                            }
// End hiding script from old browser-->

</script>

</head>
0
mayhewCommented:
>I am a learner too and always apprechiated the answers

You'll notice that I didn't post an answer.  I posted a comment offering more details.

This is a common practice on this forum that (1) saves bandwidth, time and space and (2) allows the questioner to verify that what I'm offering will answer the question.


>If you feel bad about that mblase beat you with an answer... then do it the same way next time.

mblase didn't beat me with an answer.  He just posted the same thing I said as an answer and then added an example.

Ask anyone whose been on this forum for a while and they will tell you that's a pretty rude practice.

I would never do it somebody else.  And I don't appreciate that you're endorsing that behavior.

>After all you have answered many questions in the past so you should know that this can and will always happen.

I have answered a lot of questions and it's based on that experience that I'm speaking.

It's actually pretty rare that someone else will take what I say and post it as an answer.

When it happens, it's usually an innocent error and the person politely retracts.

Again, I'm amazed that you think it's all right.


mblase, I wasn't trying to seem mean-sprited with my comment.  I'm sorry if that's the way it seemed.

But this forum is a community with etiquette.  I realize that you're not that experienced on this site and this whole thing is not really that big of a deal.

But you should know that if you go around doing that, you're going to upset some people.  And I would be remiss as an "experienced" denizen of this forum if I didn't pass on to you that that behavior is not appreciated.

On the plus side, it's good that you knew the answer and I'm sure mnewnham will appreciate the solution regardless of the source.

mnewnham, if my opinion matters to you and you find mblase's answer helpful, please feel free to award him the points.  I withdraw from the question.

Quick EE primer:
================

Do not post something as an answer unless you are positive that you have the definitive answer and that it is unique from other postings.

If you post a comment that has merit, the questioner will usually award you points.

It is very common to post as a comment and wait for the questioner to tell you to post for points.

Points are not as important as maintaining a quality environment.
0
mnewnhamAuthor Commented:
As an HTML beginner, what I really was looking for was code samples: mayhews comment doesn't really assist me. I will evaluate the examples supplied by mblase and eqbservices and based on which I believe fits my requirements the best, award the points to that person.

As a general comment:

1. remember that you are the experts, and what may appear obvious to you is a giant leap in comprehension to the rest of us.

2. Answers to questions is an inappropriate place for inter-expert squabbles.
0
mnewnhamAuthor Commented:
Ok, mblases response is pretty good, but I want it to do one more thing. It reloads the parent frame ok, but if that frame is itself in a frame, the outermost frame reloads it's default pages. How can i stop it doing this.

I have upped the points to 100.
0
brigmarCommented:
Are you saying that you want each page to detect whether it's in a frame.. and if not, to load a frameset AND then place itself in that frameset ?

Unless you want to write a frameset page for "every" page, it becomes a little complex.

if you just wish to launch the "site" in a frame, and let them navigate to that page, then it is a simple matter..

in each page you want to detect, use:

if(top==self)
  top.location = 'http://mysite.com/frameset.htm';


Brian
0
brigmarCommented:
( as declared earlier by eqbservices.. )
0
mnewnhamAuthor Commented:
Not quite what I was looking for but reasonably close.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.