Change target of links in page

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

    Change target of links in page

    Hi,

    I have a webpage with two Iframe's. I want to be able to change the
    target of all links in one frame so it will point to the other frame and
    all this from the main page. Is this possible and if so how?

    Thanks in advance, Maarten

  • Randy Webb

    #2
    Re: Change target of links in page

    Muffinman wrote:
    [color=blue]
    > Hi,
    >
    > I have a webpage with two Iframe's. I want to be able to change the
    > target of all links in one frame so it will point to the other frame and
    > all this from the main page. Is this possible and if so how?[/color]

    Yes its possible.

    Open all your pages in a text editor.
    Search and replace the target="" attributes to what you want them to be.
    Save all your pages.
    Reupload all your pages.

    Now, they are targeted properly.

    Look Ma, no Javascript!!!!

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

    Comment

    • Ivo

      #3
      Re: Change target of links in page

      "Muffinman" wrote[color=blue]
      >
      > I have a webpage with two Iframe's. I want to be able to change the
      > target of all links in one frame so it will point to the other frame and
      > all this from the main page. Is this possible and if so how?[/color]

      Make sure your iframes are properly named. Then loop through all links in
      them and adjust each link's target property accordingly:

      var f=window.frames['MyFirstFrame'].document.links ;
      var i=f.length;
      while(i--){
      f[i].target='MyOthe rFrame';
      }
      var f=window.frames['MyOtherFrame'].document.links ;
      var i=f.length;
      while(i--){
      f[i].target='MyFirs tFrame';
      }

      This looks repetetive already... I 'm sure it can be improved.
      --
      Ivo




      Comment

      • Muffinman

        #4
        Re: Change target of links in page

        First place: I'm lazy. Secondly with about a thousand pages and no
        target to replace.. this can be rather difficult.

        Maarten

        Randy Webb wrote:[color=blue]
        > Muffinman wrote:
        >[color=green]
        >> Hi,
        >>
        >> I have a webpage with two Iframe's. I want to be able to change the
        >> target of all links in one frame so it will point to the other frame
        >> and all this from the main page. Is this possible and if so how?[/color]
        >
        >
        > Yes its possible.
        >
        > Open all your pages in a text editor.
        > Search and replace the target="" attributes to what you want them to be.
        > Save all your pages.
        > Reupload all your pages.
        >
        > Now, they are targeted properly.
        >
        > Look Ma, no Javascript!!!!
        >[/color]

        Comment

        • Muffinman

          #5
          Re: Change target of links in page

          First off all: I'm lazy and what I want is usually possible... Secondly:
          with over a thousand pages and no target pressent to change, this can be
          rather difficult.

          MI

          Randy Webb wrote:
          [color=blue]
          > Muffinman wrote:
          >[color=green]
          >> Hi,
          >>
          >> I have a webpage with two Iframe's. I want to be able to change the
          >> target of all links in one frame so it will point to the other frame
          >> and all this from the main page. Is this possible and if so how?[/color]
          >
          >
          > Yes its possible.
          >
          > Open all your pages in a text editor.
          > Search and replace the target="" attributes to what you want them to be.
          > Save all your pages.
          > Reupload all your pages.
          >
          > Now, they are targeted properly.
          >
          > Look Ma, no Javascript!!!!
          >[/color]

          Comment

          • Muffinman

            #6
            Re: Change target of links in page

            Excellent, works perfect.. thanks.

            Maarten

            Ivo wrote:
            [color=blue]
            > "Muffinman" wrote
            >[color=green]
            >>I have a webpage with two Iframe's. I want to be able to change the
            >>target of all links in one frame so it will point to the other frame and
            >>all this from the main page. Is this possible and if so how?[/color]
            >
            >
            > Make sure your iframes are properly named. Then loop through all links in
            > them and adjust each link's target property accordingly:
            >
            > var f=window.frames['MyFirstFrame'].document.links ;
            > var i=f.length;
            > while(i--){
            > f[i].target='MyOthe rFrame';
            > }
            > var f=window.frames['MyOtherFrame'].document.links ;
            > var i=f.length;
            > while(i--){
            > f[i].target='MyFirs tFrame';
            > }
            >
            > This looks repetetive already... I 'm sure it can be improved.
            > --
            > Ivo
            > http://www.vansandick.com/
            >
            >
            >[/color]

            Comment

            • Randy Webb

              #7
              Re: Change target of links in page

              Muffinman wrote:[color=blue]
              > First off all: I'm lazy and what I want is usually possible... Secondly:
              > with over a thousand pages and no target pressent to change, this can be
              > rather difficult.[/color]

              Your laziness is obvious by your lack of ability to scroll down, snip,
              and reply in order. But I wouldn't expect you to understand that.

              As for cycling through all your links, what target attribute will they
              have if the user has JS disabled?

              Furthermore, it is trivial to install Apache and PHP on a PC and then
              write a PHP script that will search all pages, remove all target
              attributes (if present) and then search them all again and add the
              target attribute. But of course, you are too lazy for that, right?

              If you are that lazy, then why should we waste our time to answer you?

              P.S. Read the FAQ via the signature. That is, if you are not too lazy to
              scroll down that far.

              --
              Randy
              comp.lang.javas cript FAQ - http://jibbering.com/faq
              Answer:It destroys the order of the conversation
              Question: Why?
              Answer: Top-Posting.
              Question: Whats the most annoying thing on Usenet?

              Comment

              • Muffinman

                #8
                Re: Change target of links in page

                [color=blue]
                >
                > Your laziness is obvious by your lack of ability to scroll down, snip,
                > and reply in order. But I wouldn't expect you to understand that.[/color]

                That's more on how I prefer to answer messages.
                [color=blue]
                >
                > As for cycling through all your links, what target attribute will they
                > have if the user has JS disabled?[/color]

                Than that user has to enable that. The site won't work anyway without JS
                and it can't be done without JS or at least it will make it a lot harder
                for the user. I'm not writing a conventional web site but more a sort
                of/part of, program..
                [color=blue]
                >
                > Furthermore, it is trivial to install Apache and PHP on a PC and then
                > write a PHP script that will search all pages, remove all target
                > attributes (if present) and then search them all again and add the
                > target attribute. But of course, you are too lazy for that, right?[/color]

                I considered that but since I can not know which pages exactly have to
                be changed this is not an option. BTW. all these pages have been created
                with php.
                [color=blue]
                >
                > If you are that lazy, then why should we waste our time to answer you?[/color]

                That's up to you. Laziness knows a few forms. For me it meant learning a
                whole lot more than I initially intended to do. Unfortunately it is a
                lot harder to do without the help of others.
                [color=blue]
                >
                > P.S. Read the FAQ via the signature. That is, if you are not too lazy to
                > scroll down that far.[/color]

                You make it sound as if laziness is a negative thing, do some more
                thinking on that. Most of what we have is build on laziness...
                Why does your kind always answer questions so aggressively? (<- These
                are usually not my experiences but more on what I read on answers in
                various groups )

                Well, I am not gonna spend more time on you..

                Maarten




                Comment

                • Randy Webb

                  #9
                  Re: Change target of links in page

                  Muffinman wrote:

                  <--snip-->
                  [color=blue][color=green]
                  >>
                  >> As for cycling through all your links, what target attribute will they
                  >> have if the user has JS disabled?[/color]
                  >
                  >
                  > Than that user has to enable that. The site won't work anyway without JS
                  > and it can't be done without JS or at least it will make it a lot harder
                  > for the user. I'm not writing a conventional web site but more a sort
                  > of/part of, program..[/color]

                  I am not sure I agree with the "lot harder for the user". User clicks a
                  button/link, something happens. Its no harder on the user whether the
                  action comes from a script or a server. The difference a JS dependency
                  makes is on the load on the server versus the client. But its moot. The
                  fact that you are creating an intra-net type application makes a huge
                  difference in the responses you get in this group.
                  [color=blue][color=green]
                  >>
                  >> Furthermore, it is trivial to install Apache and PHP on a PC and then
                  >> write a PHP script that will search all pages, remove all target
                  >> attributes (if present) and then search them all again and add the
                  >> target attribute. But of course, you are too lazy for that, right?[/color]
                  >
                  >
                  > I considered that but since I can not know which pages exactly have to
                  > be changed this is not an option. BTW. all these pages have been created
                  > with php.[/color]

                  Its a lot simpler to let PHP handle it before the page is sent to the
                  browser than it is for JS to handle it. It would only take one pass of
                  PHP through every file, replace the target's and save the files. Then it
                  never has to be done again. But when its served with one target and JS
                  has to change it, it has to do it every single time the page is loaded.

                  <--snip-->

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

                  Comment

                  • Muffinman

                    #10
                    Re: Change target of links in page



                    Randy Webb wrote:
                    [color=blue]
                    > Muffinman wrote:
                    >
                    > <--snip-->
                    >[color=green][color=darkred]
                    >>>
                    >>> As for cycling through all your links, what target attribute will
                    >>> they have if the user has JS disabled?[/color]
                    >>
                    >>
                    >>
                    >> Than that user has to enable that. The site won't work anyway without
                    >> JS and it can't be done without JS or at least it will make it a lot
                    >> harder for the user. I'm not writing a conventional web site but more
                    >> a sort of/part of, program..[/color]
                    >
                    >
                    > I am not sure I agree with the "lot harder for the user". User clicks a
                    > button/link, something happens. Its no harder on the user whether the
                    > action comes from a script or a server. The difference a JS dependency
                    > makes is on the load on the server versus the client. But its moot. The[/color]

                    This is what I meant with that you do not know what I am trying to do.
                    The whole point is to make it an offline application. As I do not have a
                    internet connection at home and I have access to an online library I
                    wrote this PHP script to download several books. With javascript I want
                    to create a menu for easier navigation through the book. Main functions
                    are working now.. but it still needs some improvement.

                    [color=blue]
                    > fact that you are creating an intra-net type application makes a huge
                    > difference in the responses you get in this group.[/color]

                    I'm not sure what you mean with this. The part of the app. we are
                    discussing now is completely offline... local..[color=blue]
                    >[color=green][color=darkred]
                    >>>
                    >>> Furthermore, it is trivial to install Apache and PHP on a PC and then
                    >>> write a PHP script that will search all pages, remove all target
                    >>> attributes (if present) and then search them all again and add the
                    >>> target attribute. But of course, you are too lazy for that, right?[/color]
                    >>
                    >>
                    >>
                    >> I considered that but since I can not know which pages exactly have to
                    >> be changed this is not an option. BTW. all these pages have been created
                    >> with php.[/color]
                    >
                    >
                    > Its a lot simpler to let PHP handle it before the page is sent to the
                    > browser than it is for JS to handle it. It would only take one pass of
                    > PHP through every file, replace the target's and save the files. Then it
                    > never has to be done again. But when its served with one target and JS
                    > has to change it, it has to do it every single time the page is loaded.[/color]


                    As I stated before: I can not exactly know which pages have to be edited
                    exept for that they are somewhere among the first twenty pages.

                    Maarten

                    Comment

                    Working...