Please disregard my previous message. Apparently the list is working normally for me again. Anwyay, I sent this message yesterday to the list but it never showed up. Here it is again. Hello, I noticed that the latest version of rails puts out XHTML strict in its default layout. I''m not very familiar with the ins and outs of xhtml, but I noticed that in XHTML strict you''re supposed to put weird CDATA wrappers around inline javascript. However, I''ve noticed that when I put them around my javascript, firefox stops executing the javascript. For example, this snippet is supposed to set the focus on a login form, but doesn''t work: <script type="text/javascript"> <!-- <![CDATA[ if (document.login.user_username.value == '''') document.login.user_username.focus() else document.login.user_password.focus() ]]> // --> </script> However, this does: <script type="text/javascript"> <!-- if (document.login.user_username.value == '''') document.login.user_username.focus() else document.login.user_password.focus() // --> </script> But as I understand it, under the rules of XHTML strict, the preceeding code would not validate. Is this also true for XHTML transitional? And if not, mightn''t it be better alternative for rails now, considering that otherwise we would be producing malformed code in order to get our apps to work? Carl
Carl- XHTML does not *require* CDATA wrappers (this is an XML-convention, FYI) around the inline JavaScript, but if you do not put those, you should escape your & and < characters to & and <, respectively. That being said, I would suggest you drop the antiquated comment bits from your inline JavaScript. This was a necessary convention before JavaScript capable browsers were widely used, but since it''s been close to 10 years since NS2 was released (which first supported JavaScript) it just seems silly and useless now. If you''re really worried about browser misinterpreting the content of <script> tags and rendering them as text, I would suggest using the "src" attribute and move the script into a static file. As to what Firefox is doing wrong... I''m not sure, but drop the wrapping comment bits and try it again. My guess is that it''ll work as expected, however, I haven''t tested that hypothesis. Cheers, Ben On Fri, 11 Feb 2005 09:34:30 -0800, Carl Youngblood <carlwork-0CEYHQKyN7s@public.gmane.org> wrote:> Please disregard my previous message. Apparently the list is working > normally for me again. Anwyay, I sent this message yesterday to the > list but it never showed up. Here it is again. > > Hello, > I noticed that the latest version of rails puts out XHTML strict in its > default layout. I''m not very familiar with the ins and outs of xhtml, > but I noticed that in XHTML strict you''re supposed to put weird CDATA > wrappers around inline javascript. However, I''ve noticed that when I > put them around my javascript, firefox stops executing the javascript. > For example, this snippet is supposed to set the focus on a login form, > but doesn''t work: > > <script type="text/javascript"> > <!-- > <![CDATA[ > if (document.login.user_username.value == '''') > document.login.user_username.focus() > else document.login.user_password.focus() > ]]> > // --> > </script> > > However, this does: > > <script type="text/javascript"> > <!-- > if (document.login.user_username.value == '''') > document.login.user_username.focus() > else document.login.user_password.focus() > // --> > </script> > > But as I understand it, under the rules of XHTML strict, the preceeding > code would not validate. Is this also true for XHTML transitional? And > if not, mightn''t it be better alternative for rails now, considering > that otherwise we would be producing malformed code in order to get our > apps to work? > > Carl > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Ben Schumacher wrote:>Carl- > >XHTML does not *require* CDATA wrappers (this is an XML-convention, >FYI) around the inline JavaScript, but if you do not put those, you >should escape your & and < characters to & and <, respectively. >That being said, I would suggest you drop the antiquated comment bits >from your inline JavaScript. This was a necessary convention before >JavaScript capable browsers were widely used, but since it''s been >close to 10 years since NS2 was released (which first supported >JavaScript) it just seems silly and useless now. If you''re really >worried about browser misinterpreting the content of <script> tags and >rendering them as text, I would suggest using the "src" attribute and >move the script into a static file. >Thanks for the information about escaping & and <. I didn''t realize that these were the only characters that needed escaping, As far as the old comments are concerned, they were not doing anything. Taking out the CDATA wrappers caused it the code to work. Carl
Ben Schumacher wrote:> Carl- > > XHTML does not *require* CDATA wrappers (this is an XML-convention, > FYI) around the inline JavaScript, but if you do not put those, you > should escape your & and < characters to & and <, respectively. > That being said, I would suggest you drop the antiquated comment bits > from your inline JavaScript. This was a necessary convention before > JavaScript capable browsers were widely used, but since it''s been > close to 10 years since NS2 was released (which first supported > JavaScript) it just seems silly and useless now. If you''re really > worried about browser misinterpreting the content of <script> tags and > rendering them as text, I would suggest using the "src" attribute and > move the script into a static file. >Thanks for the information about escaping & and <. I didn''t realize that these were the only characters that needed escaping, As far as the old comments are concerned, they were not doing anything. Taking out the CDATA wrappers caused it the code to work. Carl