xhtml validation javascript - javascript

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
onmouseover="text.show('<br /><b>XXXXXX</b><br />')"
Validation Output: Error:
character "<" is the first character of a delimiter but occurred as data
How can I fix it?
thanks

Use > and < instead of < and >, respectively.
Alternatively, enclose the code in a <![CDATA[ ... ]]> section.

You can also keep your Javascript in a separate file and include it with <script src="path/to/script.js"></script> and avoid having to escape it at all.

Related

Is it possible to format an ugly HTML code using Javascript?

For Example I have a code like this
<!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><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body></body></html>
Above ugly code output after source format using javascript like this
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<p>Test</p>
<b>Test Format</b>
</body>
</html>
Please help me on this.....Thanks

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

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&ActivityID=553971&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&ActivityID=553971&rnd=20079.082210606393"></script>
as well.
But not understand what is the validation result means.
Kindly advise.
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.

JavaScript in Facelets causes java.lang.IllegalArgumentException: null source

I am new to Javascript and Java Server Faces and I am having the next Problem.
The Code below is working ok:
<?xml version="1.0" encoding="UTF-8"?>
<!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"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript">
function initialize()
{
alert("Testing");
}
</script>
</head>
<body onload="initialize()">
<h1 align="center">Sol-Tech</h1><br />
</body>
</html>
But when I add a FOR loop, it doesn't work:
<?xml version="1.0" encoding="UTF-8"?>
<!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"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript">
function initialize()
{
for(var i; i<3; i++)
{
alert("Test");
}
}
</script>
</head>
<body onload="initialize()">
<h1 align="center">Sol-Tech</h1><br />
</body>
</html>
Has anyone any suggestion on how to perform a FOR loop in javascript without getting an error?
Thanks in advance,
Emanuel
You're using an outdated version of Mojarra which exposes a bug wherein this kind of IllegalArgumentException: null source is incorrectly been thrown when the view file contains a XML syntax error or when the view couldn't be restored. See also java.lang.IllegalArgumentException: null source and JSF issue 1762.
If you upgrade to a newer Mojarra version (currently already 2.1.14), then you'll in this particular case get a more self-explaining XML syntax error on the character < which indicates the start of a XML element. Facelets is namely a XML based view technology and parsed by a SAX parser. You'd need to replace the XML special character < by <
for(var i=0; i<3; i++) {
alert("Test");
}
or to put the whole script in a CDATA block
<script type="text/javascript">
<![CDATA[
function initialize()
{
for(var i=0; i<3; i++)
{
alert("Test");
}
}
]]>
</script>
or to just put it in its own .js file so that it won't be parsed as XML.
<script type="text/javascript" src="script.js"></script>
See also:
Writing JavaScript for XHTML
Unrelated to the concrete problem, the JS syntax error (uninitialized var i which I've already fixed in code snippets) is actually a completely different problem and would only show an error in client side in browser's JS console and definitely not cause an exception in the server side as JS doesn't run in webserver at all, but only in webbrowser.

twitter share button doesn't count properly

I tried to change my ip then share it again but still doesn't count.
My Code:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
<title>:: my test ::</title>
</head>
<body>
Tweet
</body>
</html>
someone could help me?
Have you tried adding the JavaScript under the anchor tag.
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id))
{js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}
(document,"script","twitter-wjs");</script>
as described at https://dev.twitter.com/docs/tweet-button

Is the following valid XHTML 1.0 Transitional?

The w3c validator service complains that the following html is invalid. It does not like the ampersand(&) in my javascript. But ampersands are allowed in javascript strings, aren't they?
<!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>
<title>Page Title</title>
</head>
<body>
<script type="text/javascript">
function search(query) {
redir = "http://search.mysite.com/search?s=FIN&ref=&q=" + query;
window.location.href = redir
return false;
}
</script>
<span>This is all valid HTML</span>
</body>
</html>
All browsers will take this, but to make it valid X(HT)ML you need to put the Javascript code in a CDATA block.
Even in javascript w3c validator don't like ampersands. Try to comment your javascript from validator
<!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>
<title>Page Title</title>
</head>
<body>
<script type="text/javascript">
//<![CDATA[//><!--
function search(query) {
redir = "http://search.mysite.com/search?s=FIN&ref=&q=" + query;
window.location.href = redir
return false;
}
//--><!]]>
</script>
<span>This is all valid HTML</span>
</body>
</html>
No, it is indeed not valid. If you want to use in-line JavaScript in an XHTML file, you'll need to wrap the JavaScript in CDATA. If you don't want to do that, then you're stuck with encoding &, < and >, which in JavaScript can be quite a pain.

Categories