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

Discussion in 'Javascript' started by la_haine, Oct 28, 2003.

  1. la_haine

    la_haine Guest

    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'
     
    la_haine, Oct 28, 2003
    #1
    1. Advertising

  2. la_haine

    kaeli Guest

    In article <bnm15p$d9j$>,
    enlightened us with...
    > 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
    -------------------------------------------------
     
    kaeli, Oct 28, 2003
    #2
    1. Advertising

  3. "la_haine" <> writes:

    > 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
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Oct 28, 2003
    #3
  4. 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/




    "la_haine" <> ha scritto nel messaggio
    news:bnm15p$d9j$...
    > 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, a

    nd
    > 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'
     
    Vicomte De Valmont, Oct 29, 2003
    #4
  5. la_haine

    la_haine Guest

    kaeli <> wrote in
    news::

    > 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
     
    la_haine, Oct 29, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. D.Rudiani
    Replies:
    2
    Views:
    313
    Ken Cox [Microsoft MVP]
    Mar 8, 2005
  2. darrel
    Replies:
    8
    Views:
    370
    Jeff Dillon
    Apr 21, 2006
  3. Bob Johnson

    URL Unchanged Regardless of Page Viewed

    Bob Johnson, Jun 26, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    581
    Cowboy \(Gregory A. Beamer\)
    Jun 26, 2007
  4. Neebski

    Bypass Previously Viewed Page

    Neebski, Jun 24, 2009, in forum: HTML
    Replies:
    7
    Views:
    382
    Neredbojias
    Jun 25, 2009
  5. Gábor SEBESTYÉN

    Unless unless

    Gábor SEBESTYÉN, Jun 17, 2005, in forum: Ruby
    Replies:
    3
    Views:
    159
    Gábor SEBESTYÉN
    Jun 17, 2005
Loading...

Share This Page