【问题标题】:How to name a link using CGI.pm如何使用 CGI.pm 命名链接
【发布时间】:2011-05-19 13:13:41
【问题描述】:

我打算使用 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...
}

【问题讨论】:

    标签: html linux perl unix cgi


    【解决方案1】:

    在您的子 print_query 中,只需执行以下操作:

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

    【讨论】:

      猜你喜欢
      • 2017-08-09
      • 1970-01-01
      • 2014-11-24
      • 2017-10-02
      • 1970-01-01
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多