HTML Interview Questions and Answers -07
Which should I use, &entityname; or &#number; ?
In HTML, characters can be represented in three ways:
1. a properly coded character, in the encoding specified by the “charset” attribute of the “Content-type:” header;
2. a character entity (&entityname;), from the appropriate HTML specification (HTML 2.0/3.2, HTML 4, etc.);
3. a numeric character reference (&#number;) that specifies the Unicode reference of the desired character. We recommend using decimal references; hexadecimal references are less widely supported.
In theory these representations are equally valid. In practice, authoring convenience and limited support by browsers complicate the issue.
HTTP being a guaranteed “8-bit clean” protocol, you can safely send out 8-bit or multibyte coded characters, in the various codings that are supported by browsers.
A. HTML 2.0/3.2 (Latin-1)
By now there seems no convincing reason to choose &entityname; versus &#number;, so use whichever is convenient.
If you can confidently handle 8-bit-coded characters this is fine too, probably preferred for writing heavily-accented languages. Take care if authoring on non-ISO-8859-based platforms such as Mac, Psion, IBM mainframes etc., that your upload technique delivers a correctly coded document to the server. Using &-representations avoids such problems.
B. A single repertoire other than Latin-1
In such codings as ISO-8859-7 Greek, koi8-r Russian Cyrillic, and Chinese, Japanese and Korean (CJK) codings, use of coded characters is the most widely supported and used technique.
Although not covered by HTML 3.2, browsers have supported this quite widely for some time now; it is a valid option within the HTML 4 specifications–use a validator such as the WDG HTML Validator or the W3C HTML Validation Service which supports HTML 4 and understands different character encodings.
Browser support for coded characters may depend on configuration and font resources. In some cases, additional programs called “helpers” or “add-ins” supply virtual fonts to browsers.
“Add-in” programs have in the past been used to support numeric references to 15-bit or 16-bit code protocols such as Chinese Big5 or Chinese GB2312.
In theory you should be able to include not only coded characters but also Unicode numeric character references, but browser support is generally poor. Numeric references to the “charset-specified” encoding may appear to produce the desired characters on some browsers, but this is wrong behavior and should not be used. Character entities are also problematical, aside from the HTML-significant characters <, & etc.
C. Internationalization per HTML 4
Recent versions of the popular browsers have support for some of these features, but at time of writing it seems unwise to rely on this when authoring for a general audience.
Is there a way to prevent getting framed?
“Getting framed” refers to having your documents displayed within someone else’s frameset without your permission. This can happen accidentally (the frameset author forgot to use TARGET=”_top” when linking to your document) or intentionally (the frameset author wanted to display your content with his/her own navigation or banner frames).
To avoid “framing” other people’s documents, you must add TARGET=”_top” to all links that lead to documents outside your intended scope.
Unfortunately, there is no reliable way to specify that a particular document should be displayed in the full browser window, rather than in the current frame. One workaround is to use <BASE TARGET=”_top”> in the document, but this only specifies the default target frame for links in the current document, not for the document itself.
If the reader’s browser has JavaScript enabled, the following script will automatically remove any existing framesets:
<script type=”text/javascript”>
if (top.frames.length!=0) {
if (window.location.href.replace)
top.location.replace(self.location.href);
else
top.location.href=self.document.href;
}
</script>
An alternative script is
<script type=”text/javascript”>
function breakOut() {
if (self != top)
window.open(“my URL”,”_top”,””);
}
</script>
</HEAD>
<BODY onLoad=”breakOut()”>
Why aren’t my frames the exact size I specified?
Older versions of Netscape Navigator seems to convert pixel-based frame dimensions to whole percentages, and to use those percentage-based dimensions when laying out the frames. Thus, frames with pixel-based dimensions will be rendered with a slightly different size than that specified in the frameset document. The rounding error will vary depending on the exact size of the browser window.
Furthermore, Navigator seems to store the percentage-based dimensions internally, rather than the original pixel-based dimensions. Thus, when a window is resized, the frames are redrawn based on the new window size and the old percentage-based dimensions.
There is no way to prevent this behavior. To accommodate it, you should design your site to adapt to variations in the frame dimensions. This is another situation where it is a good idea to accommodate variations in the browser’s presentation.
How can I specify background images?
With HTML, you can suggest a background image with the BACKGROUND attribute of the BODY element. Here is an example:
<body background=”imagefile.gif” bgcolor=”#ffffff” text=”#000000″ link=”#0000ff” vlink=”#800080″ alink=”#000080″>
If you specify a background image, you should also specify text, link, and background colors since the reader’s default colors may not provide adequate contrast against your background image. The background color may be used by those not using your background image. Authors should not rely on the specified background image since browsers allow their users to disable image loading or to override document-specified backgrounds.
How can I copy something from a webpage to my webpage?
1: Plaintext or any text information viewable from your browser can be easily copied like any other text from any other file.
2; HTML and web scripts – you will need to view the web page’s source code. In the page’s source code, copying the <script> and </script> tags as well as all the information in-between these tags will usually enable the script to work on your web page.
3: Images, sounds, or movies – Almost all images, sounds, and movies can be copied to your computer and then viewed on your webpage. Images can be easily copied from a webpage by right-clicking an image and selecting “Save Picture as” or “Save Image as”. Unless the sound or movies file has a direct link to download and save the file to a specified location on your hard disk drive or to view your Internet browser’s cache and locate the sound or movie file saved in the cache.
4. Embedded objects – Looking at the source code of the object to determine the name of the file and how it is loaded, and copy both the code and the file.