Top 50 Html+javascript Interview Questions
Q1. How To Access An External Javascript File That Is Stored Externally And Not Embedded?
This can be achieved through the use of the following tag between head tags or among frame tags.
<script src="abc.Js"></script>
wherein abc.Js is the external javscript record to be accessed.
Q2. How Do You Target A Specific Frame From A Hyperlink?
Include the name of the frame within the target characteristic of the link. <a href=”mypage.Htm” target=”myframe”>>My Page</a>
Q3. How Do I Make A Frame With A Vertical Scrollbar But Without A Horizontal Scrollbar?
The handiest way to have a body with a vertical scrollbar however with out a horizontal scrollbar is to outline the frame with SCROLLING="auto" (the default), and to have content that doesn't require horizontal scrolling. There is no way to specify that a body should have one scrollbar but now not the other. Using SCROLLING="sure" will force scrollbars in both directions (even if they aren't wanted), and the usage of SCROLLING="no" will inhibit all scrollbars (even when scrolling is necessary to get admission to the body's content). There are not any other values for the SCROLLING attribute.
Q4. What Are The Problems Associated With Using Javascript, And Are There Javascript Techniques That You Discourage?
Browser model incompatibility is the biggest problem. It calls for knowing how every scriptable browser version implements its item model. You see, the incompatibility rarely has to do with the core JavaScript language (although there had been upgrades to the language over the years); the majority of incompatibility troubles should do with the object models that each browser version implements. For instance, scripters who started out with Navigator 3 carried out the photo rollover as it regarded cool. But they have been dismayed to find out that the photograph object wasn't scriptable in Internet Explorer 3 or Navigator @While there are clean workarounds to make this option work on more recent browsers with out disturbing older ones, it changed into a painful learning experience for lots.
The 2nd biggest can of worms is scripting connections between a couple of home windows. A lot of scripters want to have little home windows pop up with navigation bars or some such gizmos. But the item models, specially within the older browser variations, don't make it smooth to paintings with those windows the minute you put a person in the front of them--users who can manually close windows or change their stacking order. More recently, a glitch in some uninstall exercises for Windows ninety five programs can disturb important parts of the system Registry that Internet Explorer 4 calls for for handling a couple of home windows. A scripter can not paintings round this trouble, as it's not viable to locate the trouble in a user's machine. I generally tend to avoid more than one windows that have interaction with each other.
Q5. How Is Javascript Different From Java?
JavaScript was evolved by means of Brendan Eich of Netscape; Java changed into advanced at Sun Microsystems. While the 2 languages percentage some commonplace syntax, they have been evolved independently of every different and for exceptional audiences. Java is a complete-fledged programming language tailored for community computing; it includes masses of its personal gadgets, together with gadgets for growing user interfaces that seem in Java applets (in Web browsers) or standalone Java applications. In contrast, JavaScript is predicated on whatever surroundings it's working in for the user interface, which includes a Web file's shape factors.
JavaScript was first of all called LiveScript at Netscape even as it become below improvement. A licensing deal between Netscape and Sun at the closing minute let Netscape plug the "Java" name into the call of its scripting language. Programmers use totally extraordinary tools for Java and JavaScript. It is also not unusual for a programmer of 1 language to be ignorant of the other. The languages do not depend on each different and are intended for exclusive purposes. In a few methods, the "Java" call on JavaScript has pressured the arena's information of the differences between the two. On the opposite hand, JavaScript is lots simpler to learn than Java and might offer a mild creation for newcomers who want to graduate to Java and the kinds of packages you may broaden with it.
Q6. How Do I Keep People From Stealing My Source Code And/or Images?
Because copies of your HTML files and images are stored in cache, it is impossible to save you someone from being able to shop them onto their difficult drive. If you are involved about your pics, you may want to embed a watermark with your statistics into the photograph. Consult your photograph enhancing software's assist report for extra details.
The shades on my page appearance specific when considered on a Mac and a PC. The Mac and the PC use barely specific colour palettes. There is a 216 "browser secure" shade palette that each systems help; the Microsoft coloration picker web page has a few excellent statistics and hyperlinks to other resources approximately this. In addition, the 2 systems use one of a kind gamma (brightness) values, so a photo that appears nice at the Mac may also appearance too dark at the PC. The only way to deal with this hassle is to tweak the brightness of your photograph so that it looks suited on both structures.
Q7. Methods Get And Post In Html Forms - What's The Difference?
GET: Parameters are handed inside the querystring. Maximum amount of statistics that may be sent through the GET method is limited to approximately 2kb.
POST: Parameters are handed inside the request body. There is no limit to the amount of statistics that can be trferred using POST. However, there are limits on the most quantity of facts that may be trferred in one call/value pair.
Q8. How To Create A Function Using Function Constructor?
The following example illustrates this
It creates a feature referred to as square with argument x and returns x improved via itself.
Var rectangular = new Function ("x","return x*x");
Q9. When I Try To Upload My Site, All My Images Are X's. How Do I Get Them To Load Correctly?
They are a few reasons that this may appear. The maximum not unusual are:
You're attempting to use a .Bmp or .Tif or different non-supported record format. You can most effective use .Gif and .Jpg on the net. You need to convert documents that aren't .Gif or .Jpg right into a .Gif or .Jpg together with your picture/pics program.
You've forgotten to upload the photo files. Double-Check.
You've incorrectly related to the pictures. When you're beginning out, attempt simply the usage of the file name within the tag. If you have cat.Jpg, use
img src="cat.Jpg">.
Image document names are case-touchy. If your file is referred to as CaT.JpG, you can not type cat.Jpg, you have to kind CaT.JpG precisely within the src.
If all the above fail, re-add the photo in BINARY mode. You may also have by chance uploaded the image in ASCII mode.
Q10. Is There A Site That Shows Which Tags Work On Which Browsers?
There had been numerous attempts to do this, but I'm now not privy to any absolutely accurate supply of comparisons among the browsers. The hassle is that there are numerous one of a kind variations of every browser, and plenty of one of a kind tags. All modern-day browsers must support the tags within the legit HTML three.2 specification, however the important ones also assist nonstandard tags and every now and then have barely exclusive implementations. One place that has pretty top compatibility data is Browsercaps.
Q11. What Does The Enableviewstatemac Setting In An Aspx Page Do?
Setting EnableViewStateMac=real is a safety measure that allows ASP.NET to ensure that the viewstate for a page has now not been tampered with. If on Postback, the ASP.NET framework detects that there has been a change in the fee of viewstate that turned into despatched to the browser, it raises an errors - Validation of viewstate MAC failed.
Use <%@ Page EnableViewStateMac="true"%> to set it to actual (the default price, if this attribute isn't distinct is likewise true) in an aspx page.
Q12. What Can Javascript Programs Do?
Generation of HTML pages on-the-fly without having access to the Web server. The person may be given manipulate over the browser like User enter validation Simple computations can be finished on the purchaser's device The consumer's browser, OS, screen size, and so on. May be detected Date and Time Handling
Q13. How To Determine The State Of A Checkbox Using Javascript?
Var checkedP = window.Record.GetElementById("myCheckBox").Checked;
Q14. How To Set The Focus In An Element Using Javascript?
<script> function setFocus() if(focusElement != null) report.Forms[0].Factors["myelementname"].Focus(); </script>
Q15. How Do You Convert Numbers Between Different Bases In Javascript?
Use the parseInt() function, that takes a string because the first parameter, and the bottom as a second parameter. So to convert hexadecimal 3F to decimal, use parseInt ("3F", sixteen);
Q16. How Can I Display An Image On My Page?
Use an IMG detail. The SRC characteristic specifies the place of the photo. The ALT characteristic affords trade text for those not loading pics. For instance:
<img src="logo.Gif" alt="ACME Products">
Q17. How To Write A Script For "choose" Lists Using Javascript
@To eliminate an item from a list set it to null.
MySelectObject.Alternatives[3] = null;
@To truncate a list set its period to the maximum size you desire.
MySelectObject.Length = 2;
@To delete all alternatives in a choose object set the period to 0.
MySelectObject.Leng
Q18. What Are Javascript Types?
Number, String, Boolean, Function, Object, Null, Undefined.
Q19. How To Set A Html Document's Background Color?
Record.Bgcolor belongings may be set to any suitable colour.
Q20. What Is Negative Infinity?
It’s quite a number in JavaScript, derived by dividing bad quantity via 0.
Q21. What Does "1"+2+four Evaluate To?
Since 1 is a string, the whole lot is a string, so the end result is 124.
Q22. How Do I Make Sure My Framed Documents Are Displayed Inside Their Frame Set?
When the sub-files of a frameset country are accessed without delay, they seem with out the context of the encircling frameset.
If the reader's browser has JavaScript guide enabled, the subsequent script will repair the frameset:
<SCRIPT TYPE="text/javascript">
if (discern.Area.Href == self.Vicinity.Href)
if (window.Place.Href.Update)
window.Region.Update('frameset.Html');
else
// reasons issues with returned button, however works
window.Place.Href = 'frameset.Html';
</SCRIPT>
A extra usual method is a "restore frames" link:
<A HREF="frameset.Html" TARGET="_top">Restore Frames
Note that during either case, you should have a separate frameset document for each content material file. If you link to the default frameset record, then your reader gets the default content material record, instead of the content file he/she changed into seeking to get admission to. These frameset documents must be generated robotically, to avoid the tedium and inaccuracy of creating them by way of hand.
Note that you may paintings around the hassle with bookmarking frameset states by means of linking to these separate frameset documents the use of TARGET="_top", rather than linking to the individual content files.
Q23. How Do I Create Frames? What Is A Frameset?
Frames permit an creator to divide a browser window into more than one (square) areas. Multiple files may be displayed in a single window, every inside its very own body. Graphical browsers permit these frames to be scrolled independently of every other, and hyperlinks can update the record displayed in a single body with out affecting the others.
You can not just "add frames" to an current report. Rather, you need to create a frameset record that defines a specific aggregate of frames, and then display your content documents inside the ones frames. The frameset document have to also include opportunity non-framed content material in a NOFRAMES element.
The HTML four frames model has vast layout flaws that purpose usability problems for web customers. Frames ought to be used most effective with awesome care.
Q24. What Is The Data Type Of Variables Of In Javascript?
All variables are of item type in JavaScript.
Q25. What Does Break And Continue Statements Do?
Continue announcement keeps the current loop (if label not exact) in a brand new new release while break declaration exits the cutting-edge loop.
Q26. What Is The Difference Between A Web-garden And A Web-farm?
Web-garden - An IIS6.0 feature where you may configure an utility pool as a web-garden and also specify the quantity of employee strategies for that pool. It can assist improve performance in a few cases.
Web-farm - a general term referring to a cluster of physically separate machines, each jogging an internet-server for scalability and overall performance (comparison this with web-lawn which refers to multiple procedures on one single physical system).
Q27. How Do I Get Out Of A Frameset?
If you are the writer, this is simple. You only must upload the TARGET attribute to the link that takes readers to the meant 'outdoor' document. Give it the value of _top.
In many contemporary browsers, it isn't always possible to show a frame within the complete browser window, at least no longer very easily. The reader could want to replicate the URL of the favored frame after which request that URL manually.
I might advise that authors who need to provide readers this option add a hyperlink to the document itself within the report, with the TARGET attribute set to _top so the file presentations inside the complete window if the hyperlink is observed.
Q28. How Can Javascript Be Used To Personalize Or Tailor A Web Site To Fit Individual Users?
JavaScript permits a Web web page to perform "if-then" kinds of decisions based totally on browser model, running system, person enter, and, in more current browsers, details about the screen length in which the browser is walking. While a server CGI program could make some of the ones identical sorts of decisions, no longer anyone has access to or the know-how to create CGI applications. For instance, an skilled CGI programmer can have a look at information approximately the browser whenever a request for a web page is made; therefore a server so equipped may serve up one page for Navigator customers and a one of a kind web page for Internet Explorer users. Beyond browser and working device version, a CGI application can't know greater about the surroundings. But a JavaScript-improved page can train the browser to render handiest certain content material primarily based at the browser, operating system, and even the display screen length.
Scripting can even go further if the page writer dreams. For instance, the author may also include a choice display screen that we could the person determine the favored historical past and textual content coloration aggregate. A script can keep this statistics on the consumer in a properly-regulated neighborhood document called a cookie. The subsequent time the consumer comes to the website, scripts in its pages look to the cookie information and render the web page inside the color mixture selected previously. The server is none the wiser, nor does it have to keep any vacationer-precise facts.
Q29. Are There Any Problems With Using Frames?
The essential trouble with the layout of frames is that framesets create states within the browser that aren't addressable. Once any of the frames inside a frameset modifications from its default content material, there may be now not a manner to address the current country of the frameset. It is hard to bookmark - and impossible to link or index - the sort of frameset kingdom. It is impossible to reference one of these frameset state in different media. When the sub-files of this kind of frameset nation are accessed without delay, they appear without the context of the encompassing frameset. Basic browser features (e.G., printing, moving forwards/backwards within the browser's records) behave otherwise with framesets. Also, browsers cannot pick out which frame ought to have focus, which affects scrolling, looking, and the use of keyboard shortcuts in general.
Furthermore, frames consciousness on layout in place of on statistics structure, and lots of authors of framed sites forget to offer beneficial opportunity content material within the NOFRAMES element. Both of those elements reason accessibility problems for browsers that range considerably from the writer's expectancies and for engines like google.
Q30. How To Make A Array As A Stack Using Javascript?
The pop() and push() features flip a innocent array right into a stack
<script type="text/javascript">
var numbers = ["one", "two", "three", "four"];
numbers.Push("5");
numbers.Push("six");
record.Write(numbers.Pop());
file.Write(numbers.Pop());
report.Write(numbers.Pop());
</script>
This produces
sixfivefour
Q31. Why Do My Links Open New Windows Rather Than Update An Existing Frame?
If there's no existing frame with the call you used for the TARGET characteristic, then a new browser window will be opened, and this window might be assigned the call you used. Furthermore, TARGET="_blank" will open a new, unnamed browser window.
In HTML four, the TARGET characteristic cost is case-insensitive, so that abc and ABC both talk over with the identical body/window, and _top and _TOP each have the same which means. However, maximum browsers deal with the TARGET characteristic value as case-sensitive and do now not understand ABC as being similar to abc, or _TOP as having the unique meaning of _top.
Also, a few browsers encompass a protection characteristic that prevents documents from being hijacked via 1/3-birthday party framesets. In these browsers, if a document's hyperlink goals a body defined with the aid of a frameset report that is located on a unique server than the file itself, then the link opens in a new window alternatively.
Q32. What Is A Tag?
In HTML, a tag tells the browser what to do. When you write an HTML page, you input tags for lots motives -- to exchange the arrival of text, to show a graphic, or to make a link to every other page.
Q33. How Do I Update Two Frames At Once?
There are fundamental strategies for updating more than one frames with a single link: The HTML-based technique links to a new frameset record that specifies the new combination of frames. The JavaScript-primarily based solution makes use of the onClick characteristic of the hyperlink to replace the extra body (or frames).
The HTML-based technique can link to a brand new frameset document with the TARGET="_top" characteristic (changing the entire frameset). However, there is an opportunity if the frames to be up to date are a part of a nested frameset. In the preliminary frameset report, use a secondary frameset report to define the nested frameset. For instance:
<frameset cols="*,3*">
<frame src="contents.Html" name="Contents">
<frame src="frameset2.Html" name="Display">
<noframes>
<!-- Alternative non-framed version -->
</body></noframes>
</frameset>
A link can now use the TARGET="Display" characteristic to replace concurrently all the frames described by way of the frameset2.Html report.
The JavaScript-based totally answer uses the onClick attribute of the link to perform the secondary replace. For example:
<a href="URL1" target="Frame1" onClick="top.Frame2.Location='URL2';">Update frames
The link will replace Frame1 with URL1 usually. If the reader's browser helps JavaScript (and has it enabled), then Frame2 may also be updated (with URL2).
Q34. Are Java And Javascript The Same?
No.Java and javascript are two one-of-a-kind languages.
Java is a powerful object - orientated programming language like C++,C whereas Javascript is a customer-aspect scripting language with some limitations.
Q35. What Is The Difference Between Sessionstate And Viewstate?
ViewState is particular to a page in a session. Session nation refers to person particular statistics that can be accessed throughout all pages in the web software.
Q36. What Does The "get entry to Is Denied" Ie Error Mean?
The "Access Denied" mistakes in any browser is because of the following cause.
A javascript in one window or body is attempts to access another window or body whose document's domain is different from the record containing the script.
Q37. In A Pop-up Browser Window, How Do You Refer To The Main Browser Window That Opened It?
Use window.Opener to consult the primary window from pop-ups.
Q38. What Is The Difference Between An Alert Box And A Confirmation Box?
An alert field shows most effective one button which is the OK button while the Confirm box presentations buttons namely OK and cancel.
Q39. Are You Concerned That Older Browsers Don't Support Javascript And Thus Exclude A Set Of Web Users? Individual Users?
Fragmentation of the established base of browsers will best get worse. By definition, it may never enhance except clearly everybody in the world threw away their vintage browsers and upgraded to the latest gee-whiz variations. But even then, there are plenty of discrepancies between the scriptability of the modern-day Netscape Navigator and Microsoft Internet Explorer.
The situation makes scripting a task, mainly for inexperienced persons who might not be aware about the restrictions of in advance browsers. A lot of attempt in my books and ancillary material is going toward helping scripters recognise what features work in which browsers and the way to either workaround barriers in in advance browsers or raise the compatibility common denominator.
Designing scripts for a Web site requires making some hard selections about if, while, and the way to put in force the advantages scripting gives a page for your target audience. For public Web web sites, I propose the use of scripting in an additive way: let enough content material stand on its own, but allow scriptable browser users receive an more advantageous experience, preferably with the equal HTML record.
Q40. Can Javascript Code Be Broken In Different Lines?
Breaking is feasible within a string assertion with the aid of the use of a backslash on the give up however now not within any other javascript assertion.This is ,
record.Write("Hello international");
is possible however not document.Write
("hi there global");
Q41. What And Where Are The Best Javascript Resources On The Web?
The satisfactory place to start is some thing referred to as the meta- which presents a excessive-degree overview of the JavaScript help to be had on the Net.
For interactive help with precise issues, not anything beats the number one JavaScript Usenet newsgroup, comp.Lang.Javascript. Netscape and Microsoft additionally have vendor-precise developer dialogue corporations as well as precise documentation for the scripting and object model implementations.
Q42. How To Create Arrays In Javascript?
We can declare an array like this
var scripts = new Array();
We can upload factors to this array like this
scripts[0] = "PHP";
scripts[1] = "ASP";
scripts[2] = "JavaScript";
scripts[3] = "HTML";
Now our array scrips has four elements inside it and we will print or get admission to them with the aid of using their index range. Note that index number starts from @To get the third detail of the array we have to use the index wide variety 2 . Here is the way to get the 1/3 detail of an array.
File.Write(scripts[2]);
We can also create an array like this
var no_array = new Array(21, 22, 23, 24, 25);
Q43. What Is A Prompt Box?
A set off container lets in the consumer to enter enter by using imparting a text container.
Q44. Text From Your Clipboard?
It is genuine, text you closing copied for pasting (copy & paste) may be stolen whilst you visit web sites using a aggregate of JavaScript and ASP (or PHP, or CGI) to jot down your feasible touchy facts to a database on any other server.
Q45. How To Shift And Unshift Using Javascript?
<script type="text/javascript">
var numbers = ["one", "two", "three", "four"];
numbers.Unshift("zero");
record.Write(" "+numbers.Shift());
record.Write(" "+numbers.Shift());
document.Write(" "+numbers.Shift());
</script>
This produces
0 one two
shift, unshift, push, and dad may be used at the equal array. Queues are without difficulty implemented the use of mixtures.
Q46. What Does Isnan Function Do?
Return actual if the argument is not a variety of.
Q47. What Web Sites Do You Feel Use Javascript Most Effectively (i.E., Best-in-elegance Examples)? The Worst?
The great websites are the ones that use JavaScript so trparently, that I'm no longer conscious that there may be any scripting on the page. The worst sites are people who try to galvanize me with how tons scripting is on the web page.
Q48. What Is Javascript?
JavaScript is a fashionable-purpose programming language designed to let programmers of all ability stages manage the behavior of software program items. The language is used most extensively these days in Web browsers whose software objects generally tend to represent an expansion of HTML elements in a report and the record itself. But the language can be--and is--used with different types of objects in other environments. For example, Adobe Acrobat Forms makes use of JavaScript as its underlying scripting language to attach collectively objects which might be unique to the paperwork generated via Adobe Acrobat. Therefore, it's far crucial to distinguish JavaScript, the language, from the items it is able to talk with in any specific surroundings. When used for Web files, the scripts go without delay in the HTML files and are downloaded to the browser with the rest of the HTML tags and content.
JavaScript is a platform-independent,event-driven, interpreted client-side scripting and programming language developed by way of Netscape Communications Corp. And Sun Microsystems.
Q49. How To Embed Javascript In A Web Page?
Javascript code can be embedded in a web page between <script langugage="javascript"></script> tags
Q50. What Is A Hypertext Link?
A hypertext hyperlink is a unique tag that hyperlinks one page to any other page or aid. If you click the link, the browser jumps to the link's vacation spot.

