HTML1527: DOCTYPE expected. The shortest valid doctype is "<!DOCTYPE html>"

17.5k views Asked by At

Good day,

I am working on a c# web application, everything is working until I add in a normal JavaScript.

The html code is something as follow:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="scripts/JScript.js" type="text/javascript"></script>
<asp:ContentPlaceHolder id="headContent" runat="server">
    </asp:ContentPlaceHolder>
</head> 
<body>

<asp:ContentPlaceHolder id="title" runat="server"></asp:ContentPlaceHolder>
<asp:ContentPlaceHolder id="bodyContent" runat="server"></asp:ContentPlaceHolder>
<!-- some code here -->
</body>

The JScript.js is the JavaScript that put in.

The JavaScript code is something as follow:

function getCookie(catId) {
  var ebRand = Math.random() + '';
ebRand = ebRand * 1000000; 

document.write('<scr' + 'ipt src="HTTP://bs.serving-sys.com/Serving/ActivityServer.bs?cn=as&amp;ActivityID=553971&amp;rnd=' + ebRand + '"></scr' + 'ipt>');
}

This JavaScript function will be trigger when a link button is click.

I hit error in IE but Chrome and Mozilla is working fine.

My error in IE console is HTML1527: DOCTYPE expected. The shortest valid doctype is "<!DOCTYPE html>".

After search in Google, I try to put in

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

as new DOCTYPE, but it not working also.

and I have try put

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

inside <head></head>

But I still get the same error in IE also.

Is is problem in ContentPlaceHolder?

Other than that, I have go to W3C Markup Validation Service to do some validation of the address :

http://validator.w3.org/check?uri=HTTP%3A%2F%2Fbs.serving-sys.com%2FServing%2FActivityServer.bs%3Fcn%3Das%26amp%3BActivityID%3D553971%26amp%3Brnd%3D20079.082210606393&charset=%28detect+automatically%29&doctype=Inline&group=0

And go to http://validator.w3.org/check to put in <script src="HTTP://bs.serving-sys.com/Serving/ActivityServer.bs?cn=as&amp;ActivityID=553971&amp;rnd=20079.082210606393"></script> as well.

But not understand what is the validation result means.

What I get from IE script console Kindly advise.

1

There are 1 answers

7
Jukka K. Korpela On

IE issues a warning about <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">, because such a string is not a valid doctype according to HTML5. The warning as such has no impact on anything. It’s just part of HTML5 evangelism.

After you changed it to <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">, the issue was removed. But you probably saw the results of using some cached copy that has a wrong doctype. Testing with a fresh file (with a new name) should fix this issue.

Of course, the code as such does not validate, since the ASP tags are taken literally and interpreted as body content, but that’s a different issue.

The practical move is to use <!DOCTYPE html> as suggested. If you wish to still validate against the XHTML 1.0 specification for example, you can do this using the validator’s user interface to override the doctype.

But it’s not a big issue; you can just as well simply ignore the warning. If you have some functional errors, they are caused by something else and should be asked separately, with sufficient data provided.