Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
What is the code to make an HTML box?
I want to display the HTML code in a box without showing the HTML display itself, so other people can copy it.
thanks
3 Answers
- Chris CLv 71 decade agoFavorite Answer
Save this HTML code to a file on your computer. Then open it using your favorite browser.
You'll notice 2 different things here:
1) Use of the textarea HTML tag to display the HTML itself
2) Use of "escape sequences" so that HTML isn't interpreted, but displayed as it is. The escape sequences I used here are "<" (which displays '<'), ">" (which displays '>'), and "©" (which displays the copyright symbol).
I enhanced it a little by using the & code and put it in a DIV instead of a textarea.
<html>
<head>
<title>HTML Box</title>
</head>
<body>
<form action="#" type="post">
<textarea rows="20" cols="80">
<html>
<head>
<title>HTML Box</title>
</head>
<body>
<!-- Here is a comment that is shown in the textarea -->
And here is some <strong>bolded</strong> text, although it doesn't appear that way, because it's included within the <textarea></textarea> HTML tags.<br>
© 2008 by Me
</body>
</html>
</textarea>
</form>
And here is some <strong>bolded</strong> text, although it doesn't appear that way, because it's included within the <textarea></textarea> HTML tags.<br>
© 2008 by Me
<br><br>
And here's another way to display it:
<div style="border: 1px solid blue; width: 50%;">
And here is some <strong>bolded</strong&bt; text, although it doesn't appear that way, because it's included within the <textarea></textarea> HTML tags.<br>
© 2008 by Me
</div>
</body>
</html>
- 1 decade ago
You need to remove the HTML reserved characters less than and greater than. Here is a little webpage I wrote that will give you the HTML of a website, just replace the "www.sony.com" with your website:
It keeps messing up my code so here is a link to the html file:
http://us.f13.yahoofs.com/bc/491b0ef4_fdac/bc/My+D...
<html>
<script type="text/javascript">
// This object will get the web page for us
var xmlHttp;
// Fires when the xmlHttp object's state has changed
function xmlHttpStateChange()
{
// Check to see if it's loaded
if (xmlHttp.readyState == 4)
{
// And make sure it's OK
if (xmlHttp.status == 200)
{
var webText = xmlHttp.responseText;
// Replace the HTML markup with printable characters
webText = webText.replace(new RegExp("&", "g"), "&");
webText = webText.replace(new RegExp("<", "g"), "<");
webText = webText.replace(new RegExp(">", "g"), ">");
// These make it look pretty
webText = webText.replace(new RegExp("\n","g"), "</br>");
webText = webText.replace(new RegExp("\t","g"), " ");
webText = webText.replace(new RegExp(" ","g"), " ");
// to do... add code coloring and better formatting
document.getElementById('CodePrintout').innerHTML = webText;
}
else
{
alert("Problem retrieving data:" + xmlHttp.statusText);
}
}
}
function loadWebpage(url)
{
xmlHttp = null;
// Only works for IE, sorry
xmlHttp=new ActiveXObject("Microsoft.xmlHttp");
if (xmlHttp != null)
{
// Attach to the state change event
xmlHttp.onreadystatechange = xmlHttpStateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
else
{
alert("Your browser does not support xmlHttp.");
}
}
</script>
<body onload="loadWebpage('http://www.sony.com)">/
<div id="CodePrintout" style="position:absolute; top:0; left:0; width:640; height:480; border: solid 1px black;"></div>
</body>
</html>