2

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

0

7 Answers 7

6

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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 possible Thanks
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.
Thanks Martin i tried parent.frames['id'].src="2.html" but it didnt worked Is it possible to give parent.frames['id'].visible=true or something like this
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.
4

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?

Comments

3

Yes. Totally possible.

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

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

Comments

2

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.

Comments

1

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

Comments

0

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 -->

Comments

0

It can happen both ways..

  1. a single html file can use multiple javascript file

2.a javascript file can be used in several html files.

In first case javascript file load can be conditional based on location, user preferences, time, age group, content restriction. You can see good example when facebook loads its page. I loads number of javascritps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.