onStartTag_(tagname)()

Replace (tagname) with the actual tag name. When a start tag with the tagname is encountered, This function is called after any other start tag programs assigned to the element. For example, use the function name onStartTag_textarea if you want the function to execute when a "textarea" start tag is encountered. (New v10.9912)

NOTE: Although most function names are case-sensitive, the (tagname) part of this function name is case-insensitive.

Example 1:

This example generates a message with the current count of "h1" start tags every time an "h1" start tag is encountered.

function onStartTag_h1() {
 $h1tagcounter++;
 Message(1,MSG_MESSAGE,'This is "h1" start tag #'+toString($h1tagcounter));
}

Example 2:

This example generates a warning message if an "a" element is used without any attributes.

function onStartTag_a() {
 if !numAttributes {
  Message(1,MSG_WARNING,'This "'+CurrentTagName+'" element has no attributes.');
 }
}

Example 3:

This example checks to see if a meta tag has a name of "pwgsc.contact.email", and if so, then it makes sure that the content is a valid email address (syntax check only). If it's not, then it generates an error message.

function onStartTag_meta() {
 if hasAttWithStringValue("name","pwgsc.contact.email") {
  if hasAtt("content") {
   if !checkStringEx(0,39,getAttValueEx("content",12)) {
    Message(1,MSG_ERROR,'Bad email address: '+$checkstringex39details,getAttValueLocation("content"));
   }
  }
 }
}

Example 4:

This example checks that the content of certain meta data is meaningful (it's not empty or only whitespace).

function onStartTag_meta() {
 if hasAtt('name') {
  $namevalue=getAttValue('name');
  if $namevalue=='dcterms.title' { checkMetaDataNonWhitespace(); }
  elseif $namevalue=='dcterms.subject' { checkMetaDataNonWhitespace(); }
  elseif $namevalue=='dcterms.language' { checkMetaDataNonWhitespace(); }
  elseif $namevalue=='dcterms.creator' { checkMetaDataNonWhitespace(); }
 }
}
 
function checkMetaDataNonWhitespace() {
 if hasAtt('content') {
  $contentindex=getAttIndex('content');
  if checkStringEx(0,33,getAttValue($contentindex)) {
   Message(1,MSG_ERROR,'The "content" value is empty or contains only whitespace characters. Meaningful text is required.',getAttValueLocation($contentindex));
  }
 }
}

Example 5:

Store a link from "link" element in a variable and append it to a log file with writeFile(). Note that writeFile() must be enabled (see its documentation page for more information).

function onStartTag_link() {
 if getAttValueEx('rel',12)=='amphtml' {
  $amphtmlurl=getAttValueEx('href',12);
  writeFile('ampurls.txt',$amphtmlurl,5); // append to log file
 }
}

Example 6:

Generate a message every time a stylesheet link is encountered. The MessageEx() function is used and a message ID of 2017041800 is assigned to any generated messages.

function onStartTag_link() {
 if getAttValueEx('rel',12)=='stylesheet' {
  MessageEx(5,2017041800,MSG_MESSAGE,'Stylesheets','Stylesheet found: '+getAttValueEx('href',12), getAttValueLocation('href'));
 }
}

Example 7:

Generate an error message anytime the "align" or "valign" attribute is used with a "td" element (even in HTML4 documents).

function onStartTag_td() {
 if hasAtt('align','valign') {
  Message(1,MSG_ERROR,'This table cell uses the "align" and/or "valign" attribute.');
 }
}