You can implement hook_preprocess_page()
, and alter the value of $variables['body_classes']
, which contains a list of CSS classes separated with a comma.
In Drupal 6, code similar to the following one should work:
function mymodule_preprocess_page(&$variables) {
$headers = drupal_get_headers();
if (preg_match('@HTTP/1\.[01]\x20+403@', $headers)) {
$variables['body_classes'] .= 'error-403,';
}
elseif (preg_match('@HTTP/1\.[01]\x20+404@', $headers)) {
$variables['body_classes'] .= 'error-404,';
}
}
Replace "error-403" and "error-404" with the actual CSS classes you want to use.
This is similar to the code I have used in a module hosted on Drupal.org, which had to detect when Drupal 6 shown an "access denied" page, or a "page not found" page.