Actually, I have a strange demand. Here I have the HTML code, and I have to pass this code to the document.write function. To achieve this, I have to make this javascript variable code and pass this document.write code. Let me explain this with an example. Say if we have code below HTML
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Then the equivalent JavaScript variable is as follows
var myVariable = '<!DOCTYPE html>\n<html>\n<head>\n<title>Page Title<\/title>\n<\/head>\n<body>\n\n<h1>This is a Heading<\/h1>\n<p>This is a paragraph.<\/p>\n\n<\/body>\n<\/html>\n';
So, we can use this variable in the document.write function as follows
<!DOCTYPE html>
<html>
<body>
<script>
var myVariable = '<!DOCTYPE html>\n<html>\n<head>\n<title>Page Title<\/title>\n<\/head>\n<body>\n\n<h1>This is a Heading<\/h1>\n<p>This is a paragraph.<\/p>\n\n<\/body>\n<\/html>\n';
document.write(myVariable);
</script>
</body>
</html>
, JavaScript, on-line- . HTML- sting . , JavaScript . Ruby on Rails, , .