How do we get JavaScript onto a web page?

Answer

You can use several different methods of placing javascript in you pages.
You can directly add a script element inside the body of page.
1. For example, to add the "last updated line" to your pages, In your page text, add the following:
<p>blah, blah, blah, blah, blah.</p>
<script type="text/javascript" >
<!-- Hiding from old browsers
document.write("Last Updated:" +

document.lastModified);
document.close();
// -->
</script>
<p>yada, yada, yada.</p>
(Note: the first comment, "<--" hides the content of the script from browsers that don't understand
javascript. The "// -->" finishes the comment. The "//" tells javascript that this is a comment so
javascript doesn't try to interpret the "-->". If your audience has much older browsers, you should put
this comments inside your javascript. If most of your audience has newer browsers, the comments can
be omitted. For brevity, in most examples here the comments are not shown. )
The above code will look like this on Javascript enabled browsers,
2. Javascript can be placed inside the <head> element
Functions and global variables typically reside inside the <head> element.
<head>
<title>Default Test Page</title>
<script language="JavaScript" type="text/javascript">
var myVar = "";
function timer(){setTimeout('restart()',10);}
document.onload=timer();
</script>
</head>
Javascript can be referenced from a separate file
Javascript may also a placed in a separate file on the server and referenced from an HTML page. (Don't
use the shorthand ending "<script ... />). These are typically placed in the <head> element.
<script type="text/javascript" SRC="myStuff.js"></script>


All javascript Questions

Ask your interview questions on javascript

Write Your comment or Questions if you want the answers on javascript from javascript Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---