Solved

.js file

Posted on 2000-05-10
13
236 Views
Last Modified: 2012-05-04
Hi Experts
I would like to know the concept of .js file.
Is it like a include file?
Is it cached by the browser?
How do i wirte it?
Can i have all my javascript functions in it?

Any information /links /sites will be of help.

Thnx
Kunal
0
Comment
Question by:jkunal
  • 5
  • 5
  • 3
13 Comments
 
LVL 1

Expert Comment

by:yatest5
ID: 2799339
Kunal,

You're in the wrong question area here - JavaScript has nothing to do with Java.  But never mind...

Javascript functions can be placed in HTML within <SCRIPT></SCRIPT> tags, but sometimes it is nice to separate functionality from the HTML.  This can be accomplished by putting all the JavaScript code in a .js file (without the SCRIPT tags) and referencing it in the HTML as

<SCRIPT SRC=myfile.js>
</SCRIPT>

The advantages of this are that you can reuse code in several different web pages and also that people viewing the source of the page cannot see you JavaScript functions.

There's not much more to say than that - but a useful JavaScript tutorial page is

http://www.tactika.com/realhome/realhome.html

Good luck,

Tom
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 2799554
1. Yes, a js file is indeed like an include file, you can use it in many of your pages by just including it
2. Yes, when the page is viewed it finds out there is an js file which should be loaded, it loads the file and keeps it in it's memory...(not really cached!!)...
3. You write it just like you normally write your javascript functions. But without the <script><!-- and //--></script> tags.
4. yes, all of your javascript functions.

to include the js file, you do:
<script src="yourjsfile.js">
</script>

and you can use all the functions.

Good luck coding!
CJ


0
 
LVL 4

Author Comment

by:jkunal
ID: 2800707
Thnx CJs, but how do i call those functions at the client.When i try calling it like the normal function it gives an object required error.
0
 
LVL 1

Expert Comment

by:yatest5
ID: 2800741
EXAMPLE

HTML FILE (whatever.html)

<HTML>
<BODY onLoad=hello()>
yada yada
<SCRIPT src="script.js">
</SCRIPT>
</BODY>
</HTML>

JS FILE (script.js)

function hello()
{
   alert('hello');
}

Put these in the same directory and load the HTML to see .js files in action.

Cheers,

Tom

0
 
LVL 22

Accepted Solution

by:
CJ_S earned 70 total points
ID: 2800751
Ok, a li'l sample. The .js file:

// start of js file, test.js

function showM(Str)
{
   alert(Str);  
}

// End of js file


// html file

<html>
<head>
<script src="test.js">
</script>
</head>

<body>
<script language=javascript>
<!--
   showM("hi");
//-->
</script>

</body>

// end of html file
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 2800763
huh, he wrote the same as I did *LOL*
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 4

Author Comment

by:jkunal
ID: 2803162
Thnx Cjs and yatest5 for your inputs.
0
 
LVL 1

Expert Comment

by:yatest5
ID: 2803740
MOAN MOMENT

How come I gave exactly the same answer as CJ_S BEFORE him and didn't get my answer accepted?

MOAN MOMENT OVER

Never mind,

Cheers,

Tom
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 2803771
probably because that was only an example of what I explained before>??
0
 
LVL 1

Expert Comment

by:yatest5
ID: 2803797
That is true, but if you look above what you wrote before - I have written almost exactly the same previously to your comment.

Whatever.
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 2803859
true, within 1 minute I posted the same...

never mind,
0
 
LVL 4

Author Comment

by:jkunal
ID: 2803951
Hi yatest5

The points were not only for that post but also for the one before that(Thursday, May 11 2000 - 03:26PM IST).
Anyway i should have shared points but, then i think EE should provide that kinda functionality.

I am sorry if i hurt you.

Kunal
0
 
LVL 1

Expert Comment

by:yatest5
ID: 2803963
Don't worry about it - I'm OK.

Tom

PS I'm turning off e-mail notification for this question now.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now