Log in   Register a New Account

Accessify Forum - Discuss Website Accessibility

New to the forum?

Only an email address is required.

Register Here

Already registered? Log In

Currently Online

No registered users are online.

get doc dec info

Reply with quote Anyone know a simple way to get doctype declaration/definition info useing javascript. Only needs to work in IE

e.g.

This sort of thing:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

Cheers

creator of Talklets
Talklets ,
Reply with quote OK how does that work. The second I give up and ask a forum, I find the goodies I need. I've not tested, but this certainly looks like the trick:

Code:
 /******************************
            Version info "object"
         ******************************/
       function versionInfo()
       {
            this.xhtml="";
            this.version="";
            this.importance="";
       }
        function detectDoctype(){
             var re=/\s+(X?HTML)\s+([\d\.]+)\s*([^\/]+)*\//gi;
             var myversionInfo=new versionInfo();
              /*********************************************
                     Just check for internet explorer.
               **********************************************/
                if(typeof document.namespaces != "undefined"){
                if(document.all[0].nodeType==8)
                    re.exec(document.all[0].nodeValue);
                else
                     return null;
                }else{
                     if(document.doctype != null)
                      re.exec(document.doctype.publicId);
                    else
                     return null;
                }
         myversionInfo.xhtml=RegExp.$1;
         myversionInfo.version=RegExp.$2;
         myversionInfo.importance=RegExp.$3;
         return myversionInfo;
      }
        var myversionInfo=detectDoctype();
            if(myversionInfo != null){
                    alert(myversionInfo.xhtml);
                   alert(myversionInfo.version);
                    alert(myversionInfo.importance);
            }
            else{
                alert("There is no DOCTYPE in the code!");
            }

creator of Talklets
Talklets ,
Reply with quote
Phil Teare wrote:
OK how does that work. The second I give up and ask a forum, I find the goodies I need.


That would be Murphy's Law of Google. Smile
Reply with quote Why do you need to sniff the doctype with JS? If you want the rendering mode you can use document.compatMode.

Simon Pieters

Display posts from previous:   

All times are GMT

  • Reply to topic
  • Post new topic