如何使用CGI.pm命名链接

时间:2010-12-03 04:17:51

标签: html linux perl unix cgi

我打算使用CGI.pm创建以下HTML 它只包含2帧。

--------------------------------
   Frame1          |
   link1           |  Frame2
   link2           |
   etc             |
---------------------------------

用户将单击第1帧中的链接,结果将显示 在第2帧中。

为此,我想在Frame1的cgi脚本中命名为“link1”等(作为查询), 然后出现在Frame2中(作为响应)。 我不确定如何在CGI中实现这一点。

这是我目前的剧本:

#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:standard/;


my $TITLE = "My title";
my $query = new CGI;
my $path_info = $query->path_info;


print $query->header();

$path_info = $query->path_info();


# If no path information is provided, then we create 
# a side-by-side frame set
if (!$path_info) {
      &print_frameset;
      exit 0;
}


&print_html_header;
&print_query if $path_info=~/query/;
&print_response if $path_info=~/response/;


&print_end;

sub print_html_header {  
print 
    $query->start_html(-title =>'My title',
       -bgcolor=> "F5F5EB",      
       -style => {
            -src => '../print.css',   
            -align=>'center',         
       }
    ),p;
}


sub print_end {
       print $query->end_html;
 }

# Create the frameset
sub print_frameset {
    my $script_name = $query->script_name;
    print <<EOF;
<html><head><title>$TITLE</title></head>
<frameset cols="35,65" frameborder=0 marginwidth=0 noresize>
<frame src="$script_name/query" name="query">
<frame src="$script_name/response" name="response">
</frameset>
EOF
   ;
    exit 0;
}


sub print_query {
    $script_name = $query->script_name;

    print "<H1>Frame1</H2>\n";

   # This is where I want to name "Link1" so that
   # it can be called later in response frame

   # But this doesn't seem to work
   print h3("Link1", -name =>'link1");

}

sub print_response {
   print "<H1>Frame2</H2>\n";
   # If name == link1 do something...
}

1 个答案:

答案 0 :(得分:1)

在子print_query中,只需执行:

print a({-href=>"$script_name/whatever_you_want", -target=>'response'}, "Link1"),