Cockneyphil has asked for the wisdom of the Perl Monks concerning the following question:

If the code: <A TARGET=info HREF=$ENV{'SCRIPT_NAME'}\??item\&$kb\&$kc> $cust</a> Gives me a link that outputs to frame "info" how can I change it to do the same by using an IF statement and not by clicking the link

Replies are listed 'Best First'.
Re: IF..output to frame
by thpfft (Chaplain) on Aug 03, 2002 at 12:36 UTC

    If you're talking about dynamically choosing the target of the link in response to another action on the page, you can't do it in perl. You can only target links on the client side: the server doesn't know anything about your frames or their relations. It just sends back the page it's asked for, and the browser takes care of displaying it in the right place. You'd need some javascript.

    But just in case you're talking about the point where you return the page containing the link, as the $cust in your snippet suggests, then here's one of the approximately 17,354 ways to do it:

    my $target = ($use_foo) ? 'foo' : 'bar'; print qq|<a href="..." target="$target"> $cust</a>|;

    you'll find many more in perlsyn.

Re: IF..output to frame
by Cine (Friar) on Aug 03, 2002 at 12:22 UTC
    I'm not quite sure what you are asking for. Your HTML is a <a> tag which references to a frame, it has nothing to do with perl but rather the browser looking at your HTML.
    If you want a specifik action _in the browser_ you should use javascript. If you want to change the HTML _before_ it is shown in the browser you can alter your script to output some different HTML...

    T I M T O W T D I
Re: IF..output to frame
by TheFifthDeuce (Novice) on Aug 03, 2002 at 17:55 UTC
    my($url1, $url2, $url3); $url1 = "$ENV{'SCRIPT_NAME'}\??item\&$kb\&$kc"; $url2 = "http://blah"; $url3 = "http://blah2"; if($foo1){ &update_frame($url1); } elsif($foo2){ &update_frame($url2); } else{ &update_frame($url3); } sub update_frame{ my($url) = $_[0]; print <<HTML; <script language = 'JavaScript'> <!-- parent.info.location = "$url"; //--> </script>; HTML }


    Just make sure you have a frame named 'info'...otherwise change the word 'info' to whatever the name of your frame is.

    David

      Under normal cicumstances that would always refresh the page on which the link is clicked, which isn't really ideal. What you really want is to mimic normal browser behaviour but with server-side flexibility and control.

      but it occurs to me that this could be a good solution if combined with a very small, preferably blank, routing frame. All links should be target="trampoline" and the very small, quick page returned to the trampoline frame could force the selected content frame to refresh.

      but op would still be using two or more cgi calls, as well as the javascript, where one at most should do it. it's going to be slow and ungainly and have way too many points of possible failure.

      /will can't remember the last time frames seemed like a good idea, but thinks netscape 2 was still a novelty at the time...

Re: IF..output to frame
by valdez (Monsignor) on Aug 03, 2002 at 12:56 UTC

    Please, can you explain with more details your problem?