|
JavaScript Tip:
Ask Visitors For Help
by Larisa Thomason,
Senior Web Analyst,
NetMechanic, Inc.
Slow-loading pages annoy visitors, but another common Web site mistake is even worse: broken links. This bit of JavaScript makes it easy for visitors to report broken links. Invite visitors to alert you to problems before you lose credibility and customers!
Broken Links Reduce Credibility
It's aggravating to realize that you can spend hours creating a site navigation system and months working with other webmasters to build link popularity, only to have your credibility diminished when visitors find broken links on your site.
You can control your own site organization and your internal navigation system. However, you're helpless when thoughtless webmasters reorganize their sites and change file names or paths. Don't be a culprit yourself! Always check your backlinks before you make major structural changes to your site.
Unfortunately, Web site visitors blame YOU and not the other site when they find broken external links.
HTML Toolbox's Link Check feature alerts you to broken links, but it doesn't run continuously. Depending on how often you use it, you could have broken links on your site for a day, week, or even longer! A small amount of JavaScript code added to your custom error page gives you some added insurance. Use it to invite visitors to report broken links directly to you.
Use The Referrer Property
The JavaScript referrer property gives you the address of the referring page. That is, the page that the visitor was on immediately before visiting the current page. Our July 2001 Webmaster Tip discusses how to use the referrer property to track visits, personalize Web page content, direct visitors to a particular page, and advertise special offers.
In this article, let's learn another use for the referrer property: to enhance your custom error page. First, you'll have to learn how to create a custom error page if you don't already use one on your Web site.
Get The Referrer And Create A Mailto Link
We'll need to collect the address of the referring document (that's the broken link page causes the custom error document to appear).
NOTE: remember that the referrer property only works when the page is loaded on a live Web server. If you just try this technique on your local machine, you'll never see the referring URL appear on your error page.
Add this JavaScript code to the BODY section of the document:
<script language="javascript" type="text/javascript">
if (document.referrer != '')
document.write(document.referrer);
</script> |
That adds the URL address for the broken link to the custom error page. Next, add a mailto link that invites your visitors to report the problem.
A basic mailto just contains your email address, but you can also add enhancements that define the subject, cc addresses, and even write text into the body of the document. Our September 2002 Webmaster Tip describes this in detail.
Create a mailto link that looks something like this:
<a href="mailto:YourName@YourSite.com?
&subject=Broken%20Link%20Report!">
Report this broken page!</a> |
Here's an example page that contains one link. Click on the link to see how the referrer property works and a sample mailto link. Note: the example page doesn't link to a real custom error document because we already have one set up for the NetMechanic site.
The problem with a mailto link is that the visitor has to be motivated enough to actually click on the link, open the email client, and paste the broken link into the email. It is possible to handle this without email by using a form handling CGI script to process the form instead of a basic mailto link. Check with your Web host to see if you have access to a CGI form handling script.
But this is a quick and easy way to encourage visitors to report broken links and it doesn't require you to have access to any special scripts - just a custom error document. It's not as reliable as HTML Toolbox of course, but it just takes a little time and a few lines of code to add an extra element of safety to your site.
|