The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Write out html from javascript

What is the best way to embed a js file on a site and have it write out HTML... Is there a way that document.write could write out any generic html, or is there a way to escape it so that i don't have to use ticks, etc.

I would avoid JavaScript for doing any mission-critical stuff as not all browsers support it ( for example text browsers ) or have it disabled.
Better to use a server-side technology to generate your common markup using something like "includes" or templating modules depending on the language.

UNIX-based languages can make use of "heredocs" this avoids having to over-use quoting.
Perl has functions for creating quotes - qq, q and qw - and so you can keep your literal quotes for markup.

For what I'll be doing, it will have to be JavaScript. It is a service that needs to generate generic code that can be added into any page to output HTML, which will vary from client to client.

Is there set rules that javascript cannot print out? I know that I will have to have a backslash before any quotes, but asside from that, is there anything I should worry about?

Originally Posted by Puffin the Erb

I would avoid JavaScript for doing any mission-critical stuff as not all browsers support it ( for example text browsers ) or have it disabled.
Better to use a server-side technology to generate your common markup using something like "includes" or templating modules depending on the language.

UNIX-based languages can make use of "heredocs" this avoids having to over-use quoting.
Perl has functions for creating quotes - qq, q and qw - and so you can keep your literal quotes for markup.

It is best to avoid document.write as that is invalid with XHTML and only works in HTML when run before the page finishes loading. The better way of updating the page using Javascript is to use innerHTML and the best way is to use the DOM methods.

All quotes and slashes will need to be escaped in any text that you output to your page from Javascript.

Also remember that anything written by Javascript will not be visible to 10% of your visitors so the page needs to be usable without it.