|
On certain
sites whenever we click on an external link we are first taken to a generic
"You are now leaving this site..." page (along with some disclaimer
information) before we are redirected to our actual destination. This
feature is quite easy to implement and I am going to show you how in this
tutorial.
First of all we need to create an "exit" page that is dedicated
to do the message/disclaimer displaying and redirecting. You can see the
design of my exit page (exit.asp) by clicking on the Demo link at the
end of this page.
After you have your exit page designed, switch to the HTML source and
add these to the top of your ASP page:
<%
If Request.Querystring("url") <> "" Then
xsite= "http://" & Request.Querystring("url")
Else
'specify a default page to redirect to
xsite="index.asp"
End If
%>
This will assign xsite the value of the URL parameter "url"
if there's any, or give it a default page to redirect to if there's none
to be found (this is likely to happen if users try to access your exit.asp
page directly).
Then add this line within the <head></head> tags:
<meta http-equiv="refresh" content="5;
Url=<%=xsite%>">
The meta refresh tag will redirect your users to the specifed URL after
the time in seconds specified in the content attribute. xsite is just
a variable name, you can use any name that you like. Of course, feel free
to change the number of seconds users have to wait before the redirect.
This is supposed to take care of the redirecting, isn't it? Well, I always
put the back-up plan of giving users the chance to click on the actual
link, just in case something went wrong and the users were not redirected,
or if they were simply too impatient to wait 5 seconds. So, add this to
your page:
Click <a href="http://<%=xsite%>">here</a>
if you are not redirected to your destination after 5 seconds.
Now whenever you have an external link on your site, just point your link
to exit.asp, then append the actual link's URL to the URL parameter. Study
the screen shot below and you will see immediately that UltraDev allows
you to do this easily.
If you don't get it, here are the steps:
1. Highlight the text Macromedia
which I want to make into a link.
2. Select Link on the Property Inspector (PI). Point to exit.asp.
3. Click on the "Parameters..." button near the bottom
of the PI.
4. Fill in the parameter name and value in the new window.
5. The link will look like: <a href="exit.asp?url=www.macromedia.com/">
One thing to remember is that you must put the full URL when assigning
values to the URL parameter. For example in my demo I want to redirect
to the main page of UD40. I have to put the full URL (without the http://
part): www.chronoworks.com/ud40/index.asp.
There are many other enhancements that you can add to exit.asp. One useful
example is the ability to capture the number of times the external links
have been clicked on and store the results in a database. This I will
leave to you to try out on your own.
|