Gossamer Forum
Home : Products : Links 2.0 : Customization :

Can the link properties be set based on the URL?

Quote Reply
Can the link properties be set based on the URL?
I am evaluating Links-II using templates.

I would like to have the link properties set conditionally based upon the URL.

For example, if the URL http://www.domain1.com/
I want the link to open into a new instance of the browser.

If the URL is http://www.domain2.com/ I want the link to open a new instance of the browser with the menubar and address bars disabled.

Anyonw know how to do this with templates ?

Thanks a ZILLION in advance !
-Robert
Quote Reply
Re: Can the link properties be set based on the URL? In reply to
It can be done but you need to use Javascript to do it, being sure to include a <noscript>..</noscript> tag pair for those browsers that either have Javascript turned off or don't support Javascript at all.

I have written and tested some code that appears to work in a straight HTML file and I am including how to integrate it into Links. Be aware, though, that I have NOT tested this in Links, so I am not sure it will work there. Backup your files before trying to use this.

1. Just before the </head> tag in the category.html template file, insert the following code:

Code:
<script language="JavaScript">
<!--
function MinWindow(URL)
{
window.open(URL, '_blank', '');
}
//-->
</script>

That function, when called, will open a new window with only the title bar at the top.

2. In site_html_templates.pl, replace sub site_html_link with the following code, changing "www.domain2.com" to the domain you are checking for:

Code:
sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.
my %rec = @_;
my $link_url;

if ($rec{'URL'} =~ "www.domain2.com") {
$build_detailed ?
($link_url = qq~<script language="JavaScript">
<!--
document.write("<a class=link href=javascript:history.go(0) onClick=MinWindow('$build_detail_url/$rec{$db_key}$build_extension')>$rec{'Title'}</a>")
//-->
</script>
<noscript>
<a href="$build_detail_url/$rec{$db_key}$build_extension" target="_blank">$rec{'Title'}</a>
</noscript>~) :
($link_url = qq~<script language="JavaScript">
<!--
document.write("<a class=link href=javascript:history(0) onClick=MinWindow('$build_jump_url?$db_key=$rec{$db_key}')>$rec{'Title'}</a>")
//-->
</script>
<noscript>
<a href="$build_jump_url?$db_key=$rec{$db_key}" target="_blank">$rec{'Title'}</a>
</noscript>~);
}
else {
$build_detailed ?
($link_url = qq~<a class="link" target="_blank" href="$build_detail_url/$rec{$db_key}$build_extension">$rec{'Title'}</a>~) :
($link_url = qq~<a class="link" target="_blank" href="$build_jump_url?$db_key=$rec{$db_key}">$rec{'Title'}</a>~);
}
# Set new and pop to either 1 or 0 for templates.
($rec{'isNew'} eq 'Yes') ?
($rec{'isNew'} = 1) :
(delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ?
($rec{'isPopular'} = 1) :
(delete $rec{'isPopular'});
return &load_template ('link.html', {
link_url => $link_url,
%rec,
%globals
});
}

The code checks for www.domain2.com and, if found, uses the Javascript function to open the new window with all the browser options turned off. If it is not found, a new instance of the browser (a new window) is opened normally. Note the absence of the double quotes for the most part. This is necessary for the script to work. Also note that the href=javascript:history.go(0) is required for two reasons: 1) to allow the anchor to show as a hypertext link and, 2) to ensure that the page in the current window does not change.

If the browser being used does not support Javascript or has Javascript turned off, the code between the <noscript> .. </noscript> tags is used instead. It will open the new instance of the browser normally because there is no way, without Javascript, to do otherwise.

3. Change this code in link.html:

Code:
<ul><li><a class="link" href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>"><%Title%></a>

to read:

Code:
<ul><li><%link_url%>

I am interested in how this works out for you. Please advise one way or the other.

I hope this helps.

[This message has been edited by Bobsie (edited May 22, 1999).]