views:

77

answers:

6

Hi friends, I have a javascript file main.js and five html files 1.html,2.html,3.html,4.html,5.html I want to access the javascript file main.as in all files . I have used in all of the five but I'm not able to access it . Is it possible to share the .js file among the html files.

Plz reply,

Thanks in advance

Prashant Dubey

+1  A: 

Yes. Are you using the correct path to the main.js file in your html files?

zaf
+5  A: 

Yes, it is entirely possible. That's the point of being able to have a JS file instead of having to embed all the code in the HTML.

David Dorward
thanks for your reply but sorry i was not clear with the question. What Im trying to do is 1.html has 4 frames they contain the files 2.html,3.html,4.html and 5.html. All of these 4 html's are the html generated by Flex ie have a swf embedded on them. Now on any event on 2.html i want to make 3.html visible. Is it possibleThanks
Prashant Dubey
As you've accepted an answer you might want to start a new question asking this. I think that it should be possible using parent.frames though.
Martin Smith
Thanks Martin i tried parent.frames['id'].src="2.html" but it didnt workedIs it possible to give parent.frames['id'].visible=true or something like this
Prashant Dubey
I didn't mean to unaccept the answer! My point was really that the clarified question would be sufficiently out of synch with all the answers people have posted that you are probably as well just starting a new question. I suggest you start a new question and post sufficient amounts of the source of the main frame and html2 and html3 that people can see what you're trying to do. At the moment I'm not even sure if you are talking about frames or iframes.
Martin Smith
+3  A: 

Yes. Totally possible.

Just reference it in all of the files e.g. by

<script type="text/javascript" src="Scripts/main.js"></script>
Martin Smith
+4  A: 

Hi Prashant, yes this is well possible. You merely have to include

<script type="text/javascript" src="main.js"></script>

in your HTML files, preferably near the bottom (for faster rendering). What have you done so far?

Tom Bartel
+2  A: 

Yes, it is possible.

Probably there is something wrong with the way you access the javascript from your html. Show us the <script ...>...</script> part of your html.

Dave Hinton
A: 

Create separate javascript file with .js extension with all your function in it and just include this javascript file in the head tag of all the html scripts u wanna use that in.

Like::

<html>
<head>
<script type="text/javascript" src="JavaScriptFilePath.js"></script>
</head>
<body>
<!-- use javascript -->
nik