frames revisted - friendly rediect

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ivo

    frames revisted - friendly rediect

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

    Some friendlier ones do this:
    if(top==self) document.write( '<a href=frameset>T his 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[i]+'\n'; alert(s);
    var obj; try{ obj=top.locatio n; } 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.s earch for an url
    with which to fill the main frame. Is there a way to avoid document.write
    and onload?

    Thanks,
    Ivo


  • Randy Webb

    #2
    Re: frames revisted - friendly rediect

    Ivo wrote:[color=blue]
    > Dear Newsgroup,
    > many framed sites have an ancient script in all their pages:
    > if(top==self) top.location=th eframeset[/color]

    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.
    [color=blue]
    > Some friendlier ones do this:
    > if(top==self) document.write( '<a href=frameset>T his 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[i]+'\n'; alert(s);
    > var obj; try{ obj=top.locatio n; } 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> ?[/color]

    <a href="myFramese t.html?somethin g">

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

    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.

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javas cript FAQ - http://jibbering.com/faq/

    Comment

    • Ivo

      #3
      Re: frames revisted - friendly rediect

      "Randy Webb" wrote[color=blue]
      > Ivo wrote:[color=green]
      > > Dear Newsgroup,
      > > many framed sites have an ancient script in all their pages:
      > > if(top==self) top.location=th eframeset[/color]
      >
      > 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.[/color]

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

      <snip>[color=blue][color=green]
      > > alert(top)
      > > // gives me [object]
      > > var s=''; for (var i in top) s+=i+'\t'+top[i]+'\n'; alert(s);
      > > var obj; try{ obj=top.locatio n; } catch(e) { obj=''; }
      > > // give me [access denied] (of course)
      > >
      > > I 'd rather drop the frames altogether, but the site has been like this[/color][/color]
      for[color=blue][color=green]
      > > years and the client insists. There are frames. So how would I detect[/color][/color]
      when[color=blue][color=green]
      > > it is appropriate to write:
      > > <a href=>View this page in its <b>own</b> frames.</a> ?[/color]
      >
      > <a href="myFramese t.html?somethin g">
      >
      > And then search for that something, if its there, then dont display the
      > link, otherwise do.[/color]

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

      Thanks,
      Ivo


      Comment

      • Randy Webb

        #4
        Re: frames revisted - friendly rediect

        Ivo wrote:
        [color=blue]
        > "Randy Webb" wrote
        >[color=green]
        >>Ivo wrote:[/color][/color]

        <--snip-->
        [color=blue][color=green]
        >><a href="myFramese t.html?somethin g">
        >>
        >>And then search for that something, if its there, then dont display the
        >>link, otherwise do.[/color]
        >
        >
        > So how would I read top.location.se arch when access to top.location is
        > already denied?[/color]

        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="myFramese t.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.


        --
        Randy
        Chance Favors The Prepared Mind
        comp.lang.javas cript FAQ - http://jibbering.com/faq/

        Comment

        • Ivo

          #5
          Re: frames revisted - friendly rediect

          "Randy Webb" wrote[color=blue]
          > Ivo wrote:[color=green]
          > > "Randy Webb" wrote[color=darkred]
          > >>Ivo wrote:[/color][/color]
          >
          > <--snip-->
          >[color=green][color=darkred]
          > >><a href="myFramese t.html?somethin g">
          > >>
          > >>And then search for that something, if its there, then dont display the
          > >>link, otherwise do.[/color]
          > >
          > >
          > > So how would I read top.location.se arch when access to top.location is
          > > already denied?[/color]
          >
          > Simple scenario:[/color]

          <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>
          [color=blue]
          > If I am still not making sense, I could try to throw together a sample
          > set later tonight.[/color]

          That 'd be interesting anyway.
          Thanks,
          Ivo
          [color=blue]
          > --
          > Randy
          > Chance Favors The Prepared Mind
          > comp.lang.javas cript FAQ - http://jibbering.com/faq/[/color]


          Comment

          • Randy Webb

            #6
            Re: frames revisted - friendly rediect

            Ivo wrote:
            [color=blue]
            > "Randy Webb" wrote
            >[color=green]
            >>Ivo wrote:
            >>[color=darkred]
            >>>"Randy Webb" wrote
            >>>
            >>>>Ivo wrote:[/color]
            >>
            >><--snip-->
            >>[color=darkred]
            >>>><a href="myFramese t.html?somethin g">
            >>>>
            >>>>And then search for that something, if its there, then dont display the
            >>>>link, otherwise do.
            >>>
            >>>
            >>>So how would I read top.location.se arch when access to top.location is
            >>>already denied?[/color]
            >>
            >> Simple scenario:[/color]
            >
            >
            > <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>[/color]

            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.referr er. 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.referr er 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.referr er as


            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.



            --
            Randy
            Chance Favors The Prepared Mind
            comp.lang.javas cript FAQ - http://jibbering.com/faq/

            Comment

            Working...