How To Make Links Open In New Window??

Discussion in 'Programming' started by DTHBAH2006, Sep 29, 2007.

  1. #1
    Hi,

    I'm working with the script below:

    Free_For_ All_ Links_ Version 2.2
    Copyright_ 1996-2002_ Matt Wright


    I would like to know what do I need to change on the following code to make the links open in another window instead of the window where the links are located.

    Your help is greatly appreaciated.


    ##############################################################################

    # Get the input
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

    # Split the name-value pairs
    @pairs = split(/&/, $buffer);

    foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);

    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $value =~ s/<([^>]|\n)*>//g;
    $value =~ s/<//g;
    $value =~ s/>//g;
    $FORM{$name} = $value;
    }

    if ($FORM{'url'} eq 'http://' || $FORM{'url'} !~ /^(f|ht)tp:\/\/\w+\.\w+/) {
    &no_url;
    }
    if (!($FORM{'title'})) {
    &no_title;
    }

    # Enter our tags and sections into an associative array

    %sections = ("busi","Business","comp","Computers","educ","Education",
    "ente","Entertainment","gove","Government",
    "pers","Personal","misc","Miscellaneous");

    # Suck previous link file into one big string
    open(FILE,"$filename");
    @lines = <FILE>;
    close(FILE);

    $i=1;
    foreach $line (@lines) {
    if ($line =~ /\<li\>\<a href\=\"([^\"]+)\">([^<]+)<\/a>/) {
    if ($FORM{'url'} eq $1) {
    &repeat_url;
    }
    $i++;
    }
    }

    # Open Link File to Output
    open (FILE,">$filename");

    foreach $line (@lines) { # For every line in our data

    if ($line =~ /<!--time-->/) {
    @months = ('January','February','March','April','May','June',
    'July','August','September','October','November','December');

    @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday',
    'Friday','Saturday');

    ($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
    if ($sec < 10) { $sec = "0$sec"; }
    if ($min < 10) { $min = "0$min"; }
    if ($hour < 10) { $hour = "0$hour"; }
    if ($mday < 10) { $mday = "0$mday"; }
    $year += 1900;
    $date = "on $days[$wday], $months[$mon] $mday, $year at $hour:$min:$sec";
    print FILE "<!--time--><b>Last link was added $date</b><hr>\n";
    }
    elsif ($line =~ /<!--number-->/) {
    print FILE "<!--number--><b>There are <i>$i</i> links on this ";
    print FILE "page.</b><br>\n";
    }
    else {
    print FILE $line;
    }

    foreach $tag ( keys %sections) { # For every tag
    if ( ($FORM{'section'} eq $sections{$tag}) &&
    ($line =~ /<!--$tag-->/) ) {

    print FILE "<li><a href=\"$FORM{'url'}\">$FORM{'title'}</a>\n";
    }
    }
    }

    close (FILE);

    # Return Link File
    print "Location: $linksurl\n\n";

    if ($database ne '') {
    open (DATABASE,">>$database");
    print DATABASE "$FORM{'url'}\n";
    close(DATABASE);
    }

    sub no_url {
    print "Content-type: text/html\n\n";
    print "<html><head><title>ERROR: No URL</title></head>\n";
    print "<body bgcolor=#FFFFFF text=#000000><center>";
    print "<h1>No URL</h1></center>\n";
    print "You forgot to enter a url you wanted added to the Free for ";
    print "all link page. Another possible problem was that your link ";
    print "was invalid.<p>\n";
    print "<form method=POST action=\"$linkscgi\">\n";
    print "<input type=hidden name=\"title\" value=\"$FORM{'title'}\">\n";
    print "<input type=hidden name=\"section\"";
    print "value=\"$FORM{'section'}\">\n";
    print "URL: <input type=text name=\"url\" size=50><p>\n";
    print "<input type=submit> * <input type=reset>\n";
    print "<hr>\n";
    print "<a href=\"$linksurl\">$linkstitle</a>\n";
    print "</form></body></html>\n";

    exit;
    }

    sub no_title {
    print "Content-type: text/html\n\n";
    print "<html><head><title>ERROR: No Title</title></head>\n";
    print "<body bgcolor=#FFFFFF text=#000000><center>";
    print "<h1>No Title</h1></center>\n";
    print "You forgot to enter a title you wanted added to the Free for ";
    print "all link page. Another possible problem is that you title ";
    print "contained illegal characters.<p>\n";
    print "<form method=POST action=\"$linkscgi\">\n";
    print "<input type=hidden name=\"url\" value=\"$FORM{'url'}\">\n";
    print "<input type=hidden name=\"section\"";
    print "value=\"$FORM{'section'}\">\n";
    print "TITLE: <input type=text name=\"title\" size=50><p>\n";
    print "<input type=submit> * <input type=reset>\n";
    print "<hr>\n";
    print "<a href=\"$linksurl\">$linkstitle</a>\n";
    print "</form></body></html>\n";

    exit;
    }

    sub repeat_url {
    print "Content-type: text/html\n\n";
    print "<html><head><title>ERROR: Repeat URL</title></head>\n";
    print "<body bgcolor=#FFFFFF text=#000000><center><h1>Repeat URL</h1></center>\n";
    print "Sorry, this URL is already in the Free For All Link Page.\n";
    print "You cannot add this URL to it again. Sorry.<p>\n";
    print "<a href=\"$linksurl\">$linkstitle</a>";
    print "</body></html>\n";

    exit;
    }
     
    DTHBAH2006, Sep 29, 2007 IP
  2. snapcount

    snapcount Peon

    Messages:
    6
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Change:

    print FILE "<li><a href=\"$FORM{'url'}\">$FORM{'title'}</a>\n";
    }

    To:

    print FILE "<li><a href=\"$FORM{'url'}\" target="_blank">$FORM{'title'}</a>\n";
    }

    I think that's what you're trying to do.
     
    snapcount, Sep 29, 2007 IP
  3. snapcount

    snapcount Peon

    Messages:
    6
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    shit... forgot to escape the quotes... sorry

    print FILE "<li><a href=\"$FORM{'url'}\" target=\"_blank\">$FORM{'title'}</a>\n";
    }
     
    snapcount, Sep 29, 2007 IP
  4. DTHBAH2006

    DTHBAH2006 Active Member

    Messages:
    988
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    70
    #4

    Thanks for the help but this didn't work.

    Any other suggestions?

    :confused:
     
    DTHBAH2006, Sep 30, 2007 IP
  5. snapcount

    snapcount Peon

    Messages:
    6
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Can you give me a little more info? When you say didn't work, do you mean there was a syntax error of some kind or that the links still did not open in a new window?

    I'm going to look at the code again... the first time I just glanced at it quickly and see if I can help you out.
     
    snapcount, Oct 6, 2007 IP
  6. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #6
    Could you show us what the HTML looks like when you look at the webpage's source code?

    It's likely a syntax error...or you might have an ad blocker :)
     
    zac439, Oct 7, 2007 IP