[Javascript] How to get valid XHTML when links contain "invalid characters"
Roger Roelofs
rer at datacompusa.com
Tue Jan 31 21:41:59 CST 2006
Janie,
On Jan 31, 2006, at 10:12 PM, Janie Hadsel wrote:
> This may be OT, but I've been trying to get a page with links to
> Mapquest URLs to validate according to the W3C. Since they are
> external links I've used Javascript to open them in new windows, and I
> was surprised to find that the W3C validator still viewed them as
> XHTML when they were passed to a Javascript function. Any ideas?
>
> Here's the link: http://www.gimv.org/contact/locations.htm
the & is a special character. To validate replace then with &
Also, it would be better to write the a element like this...
<a
href="http://www.mapquest.com/maps/map.adp?formtype=address&
searchtype=address&country=US&addtohistory=&
address=400+East+Church+Street&city=Frederick&state=MD&
zipcode=21701" class="maplink">view a map</a>
See <http://adactio.com/atmedia2005/> for a good example.
// add this to the script in the head section
function doMapLinks() {
if (!document.getElementsByTagName) return false;
var links = document.getElementsByTagName("a");
for (var i=0; i < links.length; i++) {
if (links[i].className.match("maplink")) {
links[i].onclick = function() {
viewMapWin(this.href);
return false;
}
}
}
}
window.onload = doMapLinks;
--
Roger Roelofs
Datacomp Appraisal Services
More information about the Javascript
mailing list