 |
HTML Help Please Search for the answer to your question before asking it! Thanks.
|
| View previous topic :: View next topic |
| Author |
Message |
willancs
Joined: 15 Jul 2005
Posts: 17
|
| Posted: Mon Dec 22, 2008 4:29 am HTML Code in JavaScript Variables |
|
|
Problem:
I want to insert a few fairly large paragraphs of text into a page on my site, which was planning on using a JavaScript document.write command on the page, and having a variable in a separate script containing the actual text. This was so that the page could be generic, and each one could have its individual JavaScript text file.
So in the page I have
Code:
<script type="text/javascript">
document.write('<p>' + howtoget + '</p>');
</script>
and in the text.js file, I have
Code:
var howtoget="Text <a href="link.html">text</a>";
This does not work, which I know is because of the links as I have tried taking them out, which does work.
So the question is, is there any way to contain HTML code in the javascript variable so that it will function as normal when put on the page?
Thank you in advance! |
|
|
|
Corey Bryant
Joined: 15 May 2004
Posts: 8748
Location: Castle Pines North, CO USA
|
| Posted: Mon Dec 22, 2008 6:59 am |
|
|
You might check out included content, there is an example there that has
Code: <!--
document.writeln("| <a href=\"/default.asp\">Home</a> | <a href=\"/about.asp\">About</a> | <a href=\"/contact.asp\">Contact</a> |");
//--> which is
Code: | <a href="/default.asp">Home</a> | <a href="/about.asp">About</a> | <a href="/contact.asp">Contact</a> |
There is also HTML to JavaScript Convertor, Convert HTML to JavaScript, or Cut & Paste HTML to JavaScript converter that might help some.
_________________
Corey
Residential Office Solutions | Mile High Merchant Accounts | Expression Web Blog |
|
|
| |
|
|
|
Powered by phpBB Search Engine Indexer
Powered by phpBB 2.0.19 © 2001, 2002 phpBB Group
|