Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problems with using < in script for Firefox

5 views
Skip to first unread message

Matthew Smith

unread,
Nov 7, 2006, 11:55:29 PM11/7/06
to dev-ext...@lists.mozilla.org
Hi

I am having some issues with an extension I am writing; I am unable to
use the < (less than) sign in scripts.

This causes a problem:

var foo='<document>';

So does this:

for (var i=0; i<foo; i++)
{
}

If I evaluate this in the JavaScript console, it works as expected. As
soon as I try to run it in my extension, I get an error like

</script>

---^

I'm sure that this must be something simple, but what?

Cheers

M

--
Matthew Smith
IT Consultancy & Accessible Web Application Development
Business: http://www.kbc.net.au/
Personal: http://www.smiffysplace.com/
LinkedIn: http://www.linkedin.com/in/smiffy

Eric H. Jung

unread,
Nov 8, 2006, 12:47:35 AM11/8/06
to dev-ext...@lists.mozilla.org
I suspect this script is in a XUL file. There are 3 ways (perhaps more) to fix this:

1. Leave the script code in the XUL file but escape XML entities appropriately; e.g., < should be < > should be > & should be & " should be " etc. (see http://www.w3schools.com/xml/xml_cdata.asp for list)
2. Move the script code into a js file. Include that file in the XUL like so:
<script src="myjs.js"/>
3. Leave the script code in the XUL file but enclose the script code in a CDATA section; i.e.:
<script>
<![CDATA[
// my code
]]>
</script>

Hi

This causes a problem:

var foo='<document>';

So does this:

</script>

---^

Cheers

M

_______________________________________________
dev-extensions mailing list
dev-ext...@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-extensions

Matthew Smith

unread,
Nov 8, 2006, 1:14:54 AM11/8/06
to Eric H. Jung, dev-ext...@lists.mozilla.org
Quoth Eric H. Jung at 11/08/2006 04:17 PM...

> I suspect this script is in a XUL file. There are 3 ways (perhaps more) to fix this:
>
> 1. Leave the script code in the XUL file but escape XML entities appropriately; e.g., < should be < > should be > & should be & " should be " etc. (see http://www.w3schools.com/xml/xml_cdata.asp for list)
> 2. Move the script code into a js file. Include that file in the XUL like so:
> <script src="myjs.js"/>
> 3. Leave the script code in the XUL file but enclose the script code in a CDATA section; i.e.:
> <script>
> <![CDATA[
> // my code
> ]]>
> </script>

Thanks Eric - yes, I was doing everything in one file until it all
works, then I'd split it up to get it neat and tidy.

The CDATA option looks best for now, until I split the js off into a
separate file.

Thanks again for your assistance.

Cheers

M


--
Matthew Smith
IT Consultancy & Web Application Development

Neil

unread,
Nov 8, 2006, 5:43:58 AM11/8/06
to
Eric H. Jung wrote:

>1. Leave the script code in the XUL file but escape XML entities appropriately; e.g., < should be < > should be > & should be & " should be " etc. (see http://www.w3schools.com/xml/xml_cdata.asp for list)
>
>

You appear to have a buggy email client. Not only is it unescaping
entities for you but it's also using incorrect SMTP line endings.

--
Warning: May contain traces of nuts.

0 new messages