blocking page views unless viewed in a particular way...

L

la_haine

I have a collection of pages that are designed to be called into an iframe
(named displayView), and the managers don't want people to be able to view
them unless they're in that iframe. If I use the following javascript:

<script language="javascript" type="text/javascript">
function bing() {
if (!top.document.displayView) {
document.writeln("sorry, you can't view this");
}
}
</script>


and use <body onload="bing">, it works in Opera and IE - displays the page
correctly if viewed through the iframe, but says 'sorry, you can't view
this' and nothing else if viewed outside of it. However, in mozilla browsers,
it doesn't work, and I get the error message regardless of how I view the
page.

Can anybody advise me on how to fix this?

--
'Masochists are people that have pleasure confused with pain. In a world that
has television confused with entertainment, doritoes confused with food, and
Dan Quayle confused with a national political leader, masochists are clearly
less mixed-up than the rest of us.'
-P.J.O'Rourke, 'Modern Manners'
 
K

kaeli

I have a collection of pages that are designed to be called into an iframe
(named displayView), and the managers don't want people to be able to view
them unless they're in that iframe. If I use the following javascript:

<script language="javascript" type="text/javascript">
function bing() {
if (!top.document.displayView) {
document.writeln("sorry, you can't view this");
}
}
</script>

What's the error say?
Is displayView the name of the iframe?

try
if (top.document == document) document.writeln("Sorry, you can't view
this.");

-------------------------------------------------
~kaeli~
Jesus saves, Allah protects, and Cthulhu
thinks you'd make a nice sandwich.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
 
L

Lasse Reichstein Nielsen

la_haine said:
I have a collection of pages that are designed to be called into an iframe
(named displayView), and the managers don't want people to be able to view
them unless they're in that iframe.

I am tempted to not reply, because I think it is a stupid idea to prevent
people from watching pages the way *they* prefer. Allowing the page to load
and then erasing it is *very* rude. So, slap him from me. Anyway ...
If I use the following javascript:

<script language="javascript" type="text/javascript">
function bing() {
if (!top.document.displayView) {

You test for the existence of a property called "displayView" in the
top frame's document. I can't see how that is connected to a frame of
that name at all.

Try:
if (window.name != "displayView") { ...
or
if (!parent.frames["displayView"]) { ...
or
if (parent.frames["displayView"] != window) { ...

document.writeln("sorry, you can't view this");

At least change the location to something useful!
location.href = "outOverviewPageWithProperLinks.html";

/L
 
V

Vicomte De Valmont

Mah I use it on my website. If a user with js enabled accesses a page
without passing from the front page 8that is, outside a global frameset, for
the index page of the site _is_ a frameset file), I set up a few tricks to
let him/her see the desired page but firstly dashing through the main page,
so reinstating it within the frameset: but maybe for an iframe you don't
truly need a frameset, it might suffice that in your file you check whether
self.location==top.location.
If that is the case, you redirect to the other page which includes the
iframe document.

That is, put this command in your iframe meant file:

if(self.location==top.location)location.href="otherfile.html";

Assuming otherfile.html is the file which includes the iframe.

it could be either simple like that, or you may append a ?plusData to the
url if you need to pass parameters emulating sort of a 'get' method in a
form..
ciao
Alberto vallini
http://www.unitedscripters.com/
 
L

la_haine

try
if (top.document == document) document.writeln("Sorry, you can't view
this.");

that did the job - thanks :)

--
We generally describe the most repulsive examples of humanity's cruelty as
brutal or bestial, implying by these adjectives that such behaviour is
characteristic of less highly developed animals such as ourselves. In truth,
however, the extremes of 'brutal' behaviour are confined to humanity; and
there is no parallel in nature to our savage treatment of each other.
- Storr, 1968
 

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,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top