frames revisted - friendly rediect

I

Ivo

Dear Newsgroup,
many framed sites have an ancient script in all their pages:
if(top==self) top.location=theframeset

Some friendlier ones do this:
if(top==self) document.write( '<a href=frameset>This page is '
+ 'supposed to be frames</a>.' )

These scripts fail when the page is loaded within somebody's else's
frameset.
Then top is not self but not a very cooperative top either. And with ever
growing security issues browsers have become quite paranoid. Even testing
for top's origin results in an error:

alert(top)
// gives me [object]
var s=''; for (var i in top) s+=i+'\t'+top+'\n'; alert(s);
var obj; try{ obj=top.location; } catch(e) { obj=''; }
// give me [access denied] (of course)

I 'd rather drop the frames altogether, but the site has been like this for
years and the client insists. There are frames. So how would I detect when
it is appropriate to write:
<a href=>View this page in its <b>own</b> frames.</a> ?

Question b:
in the frameset, a little script looks into self.location.search for an url
with which to fill the main frame. Is there a way to avoid document.write
and onload?

Thanks,
Ivo
 
R

Randy Webb

Ivo said:
Dear Newsgroup,
many framed sites have an ancient script in all their pages:
if(top==self) top.location=theframeset

Usually it is the other way around, where most pages check to see if its
being framed and breaking out. But those do exist as well where it wants
it pages back in frames. The MSDN site is the first one that comes to
mind that will put a page back in its frameset.
Some friendlier ones do this:
if(top==self) document.write( '<a href=frameset>This page is '
+ 'supposed to be frames</a>.' )

These scripts fail when the page is loaded within somebody's else's
frameset.
Then top is not self but not a very cooperative top either. And with ever
growing security issues browsers have become quite paranoid. Even testing
for top's origin results in an error:

alert(top)
// gives me [object]
var s=''; for (var i in top) s+=i+'\t'+top+'\n'; alert(s);
var obj; try{ obj=top.location; } catch(e) { obj=''; }
// give me [access denied] (of course)

I 'd rather drop the frames altogether, but the site has been like this for
years and the client insists. There are frames. So how would I detect when
it is appropriate to write:
<a href=>View this page in its <b>own</b> frames.</a> ?


<a href="myFrameset.html?something">

And then search for that something, if its there, then dont display the
link, otherwise do.
Question b:
in the frameset, a little script looks into self.location.search for an url
with which to fill the main frame. Is there a way to avoid document.write
and onload?

That was a technique I had employed for a while (before I abandoned
frames), was using a search string for two purposes. First was to find
out if it was actually in my frameset or not. The search string was
added dynamically by my scripts, so that it wasn't that easy to put my
sub-frame pages in someone elses frameset. The second purpose was so
that my frameset page could know which pages to display, based on the
search string.

Without doing it on the server, you are pretty much limited to the
search string and document.write'ing the frame tags.....

Hope this helps.
 
I

Ivo

Usually it is the other way around, where most pages check to see if its
being framed and breaking out. But those do exist as well where it wants
it pages back in frames. The MSDN site is the first one that comes to
mind that will put a page back in its frameset.

Since the only test on the MSDN pages I looked at, is (top==self), I can
easily put their pages in my own frameset... I don't even mind being framed
by another site (as long as they 're Google) but just want to detect when
this is happening..

alert(top)
// gives me [object]
var s=''; for (var i in top) s+=i+'\t'+top+'\n'; alert(s);
var obj; try{ obj=top.location; } catch(e) { obj=''; }
// give me [access denied] (of course)

I 'd rather drop the frames altogether, but the site has been like this for
years and the client insists. There are frames. So how would I detect when
it is appropriate to write:
<a href=>View this page in its <b>own</b> frames.</a> ?


<a href="myFrameset.html?something">

And then search for that something, if its there, then dont display the
link, otherwise do.


So how would I read top.location.search when access to top.location is
already denied?

Thanks,
Ivo
 
R

Randy Webb

Ivo said:
So how would I read top.location.search when access to top.location is
already denied?

Simple scenario:

----------------------------
| | |
| | |
| | |
| nav | main |
| | |
| | |
-----------------------------

All the links in the nav frame would have a search string appended. When
the links are clicked, to load them into main, when the page is loaded
you check location.search for that search string. If it exists, then you
don't display the link back to the frameset. If it doesn't exist, then
you display it.

<a href="myFrameset.html?thisPage.html">Frame this page</a>

When the frameset is loaded, it checks its own search string. If it
finds it, then it knows what page to display in the frameset.

You would also have to check top==self. If someone right clicks and Adds
to Favorites, then it would have the search string appended. When I was
doing it, I was using the current time as the search string, if the
search string was more than 60 minutes old, it kicked it out to the
frameset. I don't have those pages anymore though so I can't dig it out,
I am going on memory.

If I am still not making sense, I could try to throw together a sample
set later tonight.
 
I

Ivo

Simple scenario:

<snip scenario>

You have a great solution but not for the issue I tried to describe. Unless
the answer is I need to append search strings to all my internal links in
order to catch the rare occasion somebody is framing my page. But that 'd be
a dubious solution imho. If my page shows up in Google Images, my page is
framed by Google and will probably have that search string attached
automatically; if a human goes through the trouble of linking to my site, he
will also be(come) aware of my script. Again, I don't mind being framed, I
just want to know when to document.write

If I am still not making sense, I could try to throw together a sample
set later tonight.

That 'd be interesting anyway.
Thanks,
Ivo
 
R

Randy Webb

Ivo said:
<snip scenario>

You have a great solution but not for the issue I tried to describe. Unless
the answer is I need to append search strings to all my internal links in
order to catch the rare occasion somebody is framing my page. But that 'd be
a dubious solution imho. If my page shows up in Google Images, my page is
framed by Google and will probably have that search string attached
automatically; if a human goes through the trouble of linking to my site, he
will also be(come) aware of my script. Again, I don't mind being framed, I
just want to know when to document.write

<a href=>View this page in its <em>own</em> frames.</a>

I thought about it more last night, and realized what you were trying to
do. I mis-read it. if (top != self) seems to be the only way to know,
without errors, whether its in a frame or not. You have no way of
knowing whether its your frames or not, because of the cross-domain
security issues you mentioned with the top and self approach.

It seems that your best approach would be document.referrer. If its not
your frameset (full URL), then its either not in frames, or its in
someone elses frameset. And then produce the link. When testing, just
know that IE will give an empty string for document.referrer when
offline (I have never understood why it does that though)

This page: http://www.hikksworld.com/frames/frameset1.html

Is one that I made for another post I answered today, but the right hand
frame alerts its document.referrer as
http://www.hikksworld.com/frames/frameset1.html

If it is not in the frameset, or its in someone else's frameset, then it
will alert differently. So, checking it can tell you whether to write
the link or not.

Hope this helps.
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top