Limit the search by the end of the HTML header (if any).
(setq size (min (+ (point) size)
;; Only search forward 10 lines
(save-excursion
- (forward-line 10)
+ ;; Limit the search by the end of the HTML header.
+ (or (search-forward "</head>" size t)
+ ;; In case of no header, search only 10 lines.
+ (forward-line 10))
(point))))
(when (and (search-forward "<html" size t)
(re-search-forward "<meta\\s-+http-equiv=\"content-type\"\\s-+content=\"text/\\sw+;\\s-*charset=\\(.+?\\)\"" size t))