Ajax software
Free javascripts
↑
Main Page
The solution is pretty simple. A typical popup link looks like this:
<a href=”#“ onClick=”window.open(‘page.html’, ‘mywindow’, ‘width=800,height=600’);
i
return false;”>Click here.</a>
You could make the popup spiderable by changing the link to this:
<a href=”page.html” onclick=”window.open(this.href, ‘mywindow’, ‘width=800,height
i
=600’); return false;” target=”_blank”>Click here.</a>
This still presents a popup in a JavaScript-enabled browser. The
onclick
event uses the
window.open
method to open
this.href
— the
href
attribute of that link. Then it returns
false
to prevent the link
itself from being honored. On the other hand, the link is still present, so a search engine is able to navi-
gate to it without executing the JavaScript code.
Alternatively, you could simulate a popup by using a regular link that opens a new window via the
target=”_blank”
attribute, and have the page itself automatically resize after it displays. Technically,
it’s not
really
a popup. It’s a new window that automatically resizes — but the effect is similar. The link
for such a “popup” would look like this:
<a href=”page.html” target=”_blank”>Click here</a>
You must include JavaScript on the linked page to resize the window. To do so, place the following code
in the
onload
attribute of the document’s body tag with the appropriate parameters:
<body onload=”window.resizeTo(800, 600);”>
Additionally, you can handle the window’s
resize
event to keep the window’s size constant:
<body onresize=’setTimeout(“window.resizeTo(800, 600);”, 100);’>
Using
setTimeout
(which in this example causes the window to be resized after 100 milliseconds)
ensures the code will work with all browsers.
In addition to improving search engine visibility for your popups, you have also accomplished a usability
enhancement, because both of these popup varieties will degrade to opening content in a new browser
window via the
target=”_blank”
attribute if a user ’s JavaScript functionality is disabled.
These techniques are demonstrated in the upcoming exercise. You’ll also explore a usability concern
with spiderable popups.
Implementing Popup Navigation
Some sort of navigation should be present to allow the user to get back to the parent page if he or she
arrives at the popup through a search engine, or from an external web site. Because popups are not
usually created to contain contextual and navigational elements, this presents a problem.
122
Chapter 6: SE-Friendly HTML and JavaScript
c06.qxd:c06 10:55 122
Ajax software
Free javascripts
→