Interview Questions HTML

HTML


31. How do I detect what browser is being used?
Many browsers identify themselves when they request a document. A CGI script will have this information available in the HTTP_USER_AGENT environment variable, and it can use that to send out a version of the document which is optimized for that browser.
Keep in mind not all browsers identify themselves correctly. Microsoft Internet Explorer, for example, claims to be "Mozilla 1.2" to get at Netscape enhanced documents.
And of course, if a cache proxy keeps the Netscape enhanced document, someone with an other browser will also get this document if he goes through the cache.

32. How do I use an image instead of the standard submit button?
Use <INPUT NAME=foo TYPE=image SRC="http://url.to/image.gif"> instead of the normal submit tag. There is no way to do this for the reset button.

Note that some browsers will also send the x and y coordinates of the location where the user clicked on the image to the server. They are available as "foo.x=000&foo.y=000" in the CGI input.

33. Why is my binary file not downloaded, but shown on the screen?
Actually, the browser has downloaded the document, it is just treating it as a plain text file. This is because the server said it was a plain text file. To get the file in the helper application (or plug-in), you will have to configure the server to send out the right MIME type, and the browser to start the appropriate helper application for files with that MIME type.

34. How do I redirect someone to my new page?
The most reliable way is to configure the server to send out a redirection instruction when the old URL is requested. Then the browser will automatically get the new URL. This is the fastest way to do this. You can of course also simply put up a small page with a text like "This page has moved to http://new.url/, please adjust your bookmarks".

A Netscape-only solution, which doesn't work on other browsers, and screws up the "back" button in Netscape, is

<META HTTP-EQUIV="Refresh" CONTENT="x; URL=new.URL">

which will load the new URL after x seconds. This should go in the HEAD of the document. But if you do this, also include a short text saying "Document moved to new URL so-and-so" for other browsers.

(The screwing-up bit refers to the fact that if you press "Back" after you have been redirected, you will be taken to the document with the META refresh. Then the refresh will be activated, and so you'll jump to the page you just tried to leave.)

35. How can I show HTML examples without them being interpreted as part of my document?
Within the HTML example, first replace the "&" character with "&amp;" everywhere it occurs. Then replace the "&lt;" character with "<" and the "&gt;" character with ">" in the same way. 
Note that it may be appropriate to use the CODE and/or PRE elements when displaying HTML examples.

36. What is Favicon.ico and How to Create a Favicon Icon for Your Website

	

37. How do I use forms?
The basic syntax for a form is: <FORM ACTION="[URL]">...</FORM> 
When the form is submitted, the form data is sent to the URL specified in the ACTION attribute. This URL should refer to a server-side (e.g., CGI) program that will process the form data. The form itself should contain

* at least one submit button (i.e., an <INPUT TYPE="submit" ...> element),
* form data elements (e.g., <INPUT>, <TEXTAREA>, and <SELECT>) as needed, and
* additional markup (e.g., identifying data elements, presenting instructions) as needed.

38. How to create an HTML Back Button ?
It may be necessary to direct a visitor back to a page the page that directed them to the page they are currently reading. For example, this is a great feature to add to any error page to help get the visitor back to a working page easier.
Eg : <FORM><INPUT Type="button" VALUE="Back" onClick="history.go(-1);return true;"></FORM>

39. How to resize an image with HTML
The below steps are for users who wish to keep an image the original size but just re-size the image in HTML code. Although this is possible, we still suggest you resize an image using an image editor to help with download times. When an image is resized using the below steps it still has to load the larger image, even though it appears small in the browser.
Specify the width and height in your IMG SRC HTML tag as shown in the example below.
<img src="http://cdn.computerhope.com/computer-hope.jpg" width="200" height="85" alt="Computer Hope">

40. How can I eliminate the extra space after a </form> tag?
HTML has no mechanism to control this. However, with CSS, you can set the margin-bottom of the form to 0. For example: 
<form style="margin-bottom:0;" action=...>
You can also use a CSS style sheet to affect all the forms on a page:
form { margin-bottom: 0 ; }