Coding Problem

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

    Coding Problem

    I need to find a javascript that I can put into the header of
    a page so it does not allow the page the be contained in a frame.

    Can anyone suggest how to go about doing this?




    Fred

  • Janwillem Borleffs

    #2
    Re: Coding Problem

    Fred Atkinson wrote:[color=blue]
    > I need to find a javascript that I can put into the header of
    > a page so it does not allow the page the be contained in a frame.
    >
    > Can anyone suggest how to go about doing this?
    >[/color]

    if (parent.frames. length) top.location = location.href;


    JW



    Comment

    • Fred Atkinson

      #3
      Re: Coding Problem

      On Thu, 1 Jan 2004 16:31:20 +0100, "Janwillem Borleffs"
      <jw@jwscripts.c om> wrote:
      [color=blue]
      >Fred Atkinson wrote:[color=green]
      >> I need to find a javascript that I can put into the header of
      >> a page so it does not allow the page the be contained in a frame.
      >>
      >> Can anyone suggest how to go about doing this?
      >>[/color]
      >
      >if (parent.frames. length) top.location = location.href;
      >
      >
      >JW[/color]


      I put the following in the header of the page:

      <SCRIPT TYPE="text/javascript>"
      if (parent.frames. length) top.location = location.href
      // -->
      </SCRIPT>

      Unfortunately, my page still appears trapped in a frame when
      someone tries to use it that way appearing to show their URL as my
      page.

      In reading my original post, I can see I didn't make myself
      especially clear. So let me explain the scenario.

      I have a number of other pages linking to me. These pages
      were written as a result of an article that I wrote about using a free
      page and making a URL out of it by registering a domain name, putting
      the free page into a frame, and listing that free page in the frame.

      The problem was that when someone clicks on your links that
      they are forwarded to the new page sitll locked in a frame.

      These folks don't follow the part of my instructions where I l
      them to put 'target=top' in their links so they break out of the frame
      when they click. Thus, they could be on any site and still be showing
      a different URL in the address bar.

      These folks typically put a link to my article on their page.
      Of course, my page comes up with their URL in the address bar.

      What I want is that if my page comes up in a frame, that it
      should immediately forward to my URL so that my URL appears in the
      address field with my content, not my content with their URL.

      Thanks,


      Fred

      Comment

      • Janwillem Borleffs

        #4
        Re: Coding Problem

        Fred Atkinson wrote:[color=blue]
        > I put the following in the header of the page:
        >
        > <SCRIPT TYPE="text/javascript>"
        > if (parent.frames. length) top.location = location.href
        > // -->
        > </SCRIPT>
        >[/color]

        Try this:

        if (top.location.h ref != location.href) top.location = location.href;

        However, this will probably cause an access denied error because the frame
        that encapsules your page doesn't reside on your domain.

        Here are two ways of handling this:

        window.onerror = function () { top.location = location.href };
        if (top.location.h ref != location.href) top.location = location.href;

        Or:

        try {
        if (top.location.h ref != location.href) top.location =
        location.href;
        } catch (e) {
        top.location = location.href;
        }


        HTH,
        JW




        Comment

        • Evertjan.

          #5
          Re: Coding Problem

          Fred Atkinson wrote on 01 jan 2004 in comp.lang.javas cript:
          [color=blue]
          > I put the following in the header of the page:
          >
          > <SCRIPT TYPE="text/javascript>"
          > if (parent.frames. length) top.location = location.href
          > // -->
          > </SCRIPT>
          >[/color]

          There are two mistakes in this code

          1
          <SCRIPT TYPE="text/javascript>"

          should be

          <SCRIPT TYPE="text/javascript">

          2
          a closing

          // -->

          should only be used if there is also a starting string, but why use it?


          ==============

          Try:

          <SCRIPT>
          if (top != self) top.location.hr ef = self.location.h ref;
          </SCRIPT>

          Read the problems in:

          <http://www.quirksmode. org/js/framebust.html>




          --
          Evertjan.
          The Netherlands.
          (Please change the x'es to dots in my emailaddress)

          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: Coding Problem

            Janwillem Borleffs wrote:
            [color=blue]
            > Fred Atkinson wrote:[color=green]
            >> I need to find a javascript that I can put into the header of
            >> a page so it does not allow the page the be contained in a frame.
            >>
            >> Can anyone suggest how to go about doing this?[/color]
            >
            > if (parent.frames. length) top.location = location.href;[/color]

            Too complicated and error-prone. You check for the number of frames
            in the parent frameset, but replace the top frameset. Try this:

            if (self != top)
            {
            top.location = self.location;
            }

            You could also replace *all* occurrences of "top" with "parent".


            PointedEars

            Comment

            • Lasse Reichstein Nielsen

              #7
              Re: Coding Problem

              Thomas 'PointedEars' Lahn <PointedEars@we b.de> writes:
              [color=blue]
              > if (self != top)
              > {
              > top.location = self.location;[/color]

              I prefer
              top.location.hr ef = self.location.h ref;
              Less magic involved, although I don't think there is a browser
              where it makes a difference.
              [color=blue]
              > }
              >
              > You could also replace *all* occurrences of "top" with "parent".[/color]

              .... but if the same code was run again when the page is loaded in the
              parent, it will end up in top anyway.

              /L
              --
              Lasse Reichstein Nielsen - lrn@hotpop.com
              DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
              'Faith without judgement merely degrades the spirit divine.'

              Comment

              • Jim Ley

                #8
                Re: Coding Problem

                On Sun, 11 Jan 2004 20:22:18 +0100, Lasse Reichstein Nielsen
                <lrn@hotpop.com > wrote:
                [color=blue]
                >Less magic involved, although I don't think there is a browser
                >where it makes a difference.[/color]

                It's my recollection that there is... (it'll generate a runtime error
                if top.location is not defined or not an object)

                Of course I guess it's now incumbment on me remembering which it was,
                maybe if I mentioned it in the group.

                Jim.
                --
                comp.lang.javas cript FAQ - http://jibbering.com/faq/

                Comment

                Working...