Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

br tags will not validate in javascript code in XHTML strict

xhtml validate

  • Please log in to reply
2 replies to this topic

#1 RavenStorm

RavenStorm

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 154 posts
  • Location:Ontario, Canada
  • Learning:C, C#, PHP, (Visual) Basic, JavaScript, PL/SQL, Visual Basic .NET, Transact-SQL, Lua, ActionScript, VBScript, Others

Posted 28 October 2012 - 12:49 PM

I am going to keep looking, but does anyone know a work around for this. The code will not validate because of the br tags. It is a rework of one supplied to me that was originally full of p tags in the javascript, which of course do not validate either. The code works, but I would like it to validate.

Error type does not allow element "br" here 36
Error type does not allow element "br" here 39
Error type does not allow element "br" here 42
Error type does not allow element "br" here 45
Error type does not allow element "br" here 64
Error type does not allow element "br" here 67
Error type does not allow element "br" here 70
Error type does not allow element "br" here 73
Error type does not allow element "br" here 76
Error type does not allow element "br" here 79

There is no javascript in the head tags.


<body>
<h1><br/><br/>Discovering the Environment</h1><script type="text/javascript">
var isMac = 0;
var isWin = 0;
var isOtherOS = 0;
var isUndetected = 0;
var agent = navigator.platform.toLowerCase(); /* convert to lower case makes comparisons easier*/
/* Look for specific text in navigator.platform */
if (agent.indexOf('mac') != -1) isMac = 1;
else if (agent.indexOf('win') != -1) isWin = 1;
else if (
agent.indexOf('unix') != -1 ||
agent.indexOf('sunos') != -1 ||
agent.indexOf('bsd') != -1 ||
agent.indexOf('x11') != -1 ||
agent.indexOf('linux') != -1) isOtherOS = 1;
else ( isUndetected = 1 )document.write('This browser\'s designation is: ');
document.write(navigator.platform + '<br />');
if (isMac) {
document.write('This Browser is running in the Mac OS.' + '<br />');
}
else if (isWin) {
document.write('This Browser is running in the Microsoft Windows OS.' + '<br />');
}
else if (isOtherOS) {
document.write('RESISTANCE IS FUTILE...YOU WILL BE ASSIMULATED' + '<br />');
}
else {
document.write('Sorry, I\'m not sure what OS you are using.');
}
</script>
<script type="text/javascript">
/* convert userAgent text to lower case for easy searching*/
var agent = navigator.userAgent.toLowerCase();
/* Look for specific text in userAgent */
var isMoz = (agent.indexOf('mozilla') != -1);
var isIE = (agent.indexOf('msie') != -1);
var isSafari = (agent.indexOf('safari') != -1);
var isOpera = (agent.indexOf('opera') != -1);document.write('This browser\'s designation is: ');
document.write(navigator.userAgent + '<br />');
if (isMoz || isIE || isSafari || isOpera) {
if (isMoz) { document.write('This Browser is compatible with Mozilla.' + '<br />');
}
if (isIE) {
document.write('This Browser is compatible with Internet Explorer.' + '<br />');
}
if (isSafari) {
document.write('This Browser is compatible with Safari.' + '<br />');
}
if (isOpera) {
document.write('This Browser is compatible with Opera.' + '<br />');
}
}
else document.write('Sorry, I don\'t recognize this browser.' + '<br />');</script>
<h3>That is all there is to this document.</h3>
<p>Return to the <a href="#"> page.</a></p>
</body>


UPDATE: I decided to externalize it.
  • 0

#2 Vaielab

Vaielab

    Programming God

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1382 posts
  • Location:Quebec City
  • Programming Language:Java, C++, C#, PHP, JavaScript, Visual Basic .NET, Transact-SQL, ActionScript

Posted 28 October 2012 - 01:06 PM

To write html code inside your javascript and still be valide in xhtml, you need to tell the validator that this code is cdata, like so
<script type="text/javascript">
//<![CDATA[
var output = "<html><body><p>Hi!<\/p><\/body><\/html>";
//]]>
</script>

The 2 lines //<![CDATA[ and //]]> will make your code valide
But putting your code in a external file work too since it's not inside the html.

If you want to easily validate your xhtml code and are using firefox, I would recommand installing the html validator extension (http://users.skynet....illa/index.html)
It validate your code, and tell you your error, tell you why, and most of the time, tell you how to solve the problem (the code I posted come from the extension)
  • 0

You can now stalk me on linkedin: http://ca.linkedin.c...elle/24/b44/88/ !


#3 RavenStorm

RavenStorm

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 154 posts
  • Location:Ontario, Canada
  • Learning:C, C#, PHP, (Visual) Basic, JavaScript, PL/SQL, Visual Basic .NET, Transact-SQL, Lua, ActionScript, VBScript, Others

Posted 28 October 2012 - 02:45 PM

Thank you. I don't know why I keep forgetting that.
  • 0





Also tagged with one or more of these keywords: xhtml, validate

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download