Javascript:HTML Glossary

Aus Weis nix

Wechseln zu: Navigation, Suche

To automatically add a glossary by terms to some webpage text follow this recipe. Assumed is that we have a database of glossary terms defined in our site which can be retrieved via the URL

/showGlossary.php?g=term

In Header CSS add:


span.glossary
{
	color: #f97600;
	text-weight: bold;
	cursor: help;
}

(modify font style to taste).

In Header Javascript add:


 function showGlossary(x){
  if (""!=x) {
   if(window.open('/showGlossary.php?g='+x,'','width=425,height=400,scrollbars=1,status=0')){
    return  true;
   }
  }
  return false;
 }

In the body, process the HTML and replace all occurences of TERM with:


 <span class="glossary" onclick="showGlossary('TERM')">TERM</span>

Of course one needs to add a pahe /showGlossary.php?g= that displays the actual glossary.

Persönliche Werkzeuge