|
JavaScript Tip:
Keep Your Windows Focused
by Larisa Thomason,
Senior Web Analyst,
NetMechanic, Inc.
One common complaint among users is that many sites contain broken links, so of course you test yours regularly (don't you?). But you probably never considered that some visitors might think your links are broken when they aren't! That can happen when you use JavaScript to open new windows and control their placement. Fortunately, one single line of JavaScript code solves that problem!
Keep The Window On Top
In a previous JavaScript Tip, we showed you how to put your window where you want it using a short JavaScript function.
You can do a lot with this script:
- Advertise special offers.
- Encourage newsletter subscriptions.
- A navigation window for the rest of the site.
- A table of contents list.
|
You can even use it to send all your links to the same target window and avoid annoying visitors by cluttering their desktop with a lot of open browser windows. But, although you're trying to be helpful, that technique can sometimes confuse your visitors.
That's because some browsers keep the original window in focus (meaning it's the top browser window) when they load a page into the second browser window. Since the new page doesn't appear automatically, the visitor may just assume that the link is broken.
This effect is easier to show than describe! Follow these steps to see it in action:
- Both links open in the same browser window.
- Click on the first link and our homepage opens in a new browser window.
- Without closing it, return to this window and click on the second link to see the newsletter home page.
|
NetMechanic Home Page
Webmaster Tips Newsletter
See how the new window drops behind this window - and stays there? Control this problem by adding one line of code to your function that opens the new browser window.
All you need to do is give the new window focus by adding this line of code to your function:
winContent.focus()
The whole function looks like this. Note: If you copy and paste this function to your own Web page, make sure the definition for winContent is all on one line in the HTML code. Otherwise, the function won't work!
Then, call the JavaScript function inside your HREF tags:
See how it works now:
NetMechanic Home Page
Webmaster Tips Newsletter
Don't Annoy Visitors
Don't get too excited and misuse this! There are perfectly legitimate reasons to keep a window open in front of visitors. But don't use it to trap unwilling visitors into reading your content and/or advertisements if they're not interested. There are plenty of Web sites that don't annoy visitors and it's easy to find them. Be sure you avoid techniques that may drive people away from your site.
Visitors leave your site when you use techniques that confuse or annoy them, so it's important to identify and potential problems before you lose traffic.
Think about some Web site problems that turn you away:
HTML Toolbox can help you with all three problems. It contains a link check feature that automatically checks your links, identifies and corrects HTML coding errors that can break your page, and identifies slow-loading pages.
Although external links are useful to visitors and can help you improve your link popularity score, remember that your main goal is to keep visitors at your site - and bring them back to the site - as often as possible. For that, you need an attractive site that works for all visitors!
|