Reference a .js file from another .js file

D

Darrin

I've seen a couple threads on this that did not answer my question and
I could not add a post to them.

I've inherited a web application that is going to be replaced in the
coming months. For the time being, I would like to add the Analytics
(Urchin) script to the page, but there is no common components for the
100's of pages in the site. There is however a common javascript file
that is referenced from all of the pages.

I would like to be able to add the script for the Google Analytics
tracker to this .js file, and it would automatically be added to every
page, although the script references another .js file.

How can I reference this external javascript file from inside an
existing javascript file?

Any help would be greatly appreciated.

Thanks,
-Darrin
 
M

Matt Ratliff

I've seen a couple threads on this that did not answer my question and
I could not add a post to them.

I've inherited a web application that is going to be replaced in the
coming months. For the time being, I would like to add the Analytics
(Urchin) script to the page, but there is no common components for the
100's of pages in the site. There is however a common javascript file
that is referenced from all of the pages.

I would like to be able to add the script for the Google Analytics
tracker to this .js file, and it would automatically be added to every
page, although the script references another .js file.

How can I reference this external javascript file from inside an
existing javascript file?

Any help would be greatly appreciated.

Thanks,
-Darrin

Darrin,
I'm not sure if this is what you're looking for, but if you need
to add a reference to another script inside of an existing one, I've
accomplished this in the past using the following:

In my .js file I add write a reference to the external .js file:

document.write('<script type="text/javascript" language="javascript"
src="http:/somedomain/javascript/standard.js"></script>')
I can then access any objects, etc.. from the external script.
Hope this helps.

Matt
 
D

Darrin

I was going to try that, but I read on some other posts that it did not
work and had some "system-wide impacting" results. ;-)

I will certainly give that a try. That should work perfectly for me.

Thank you!

-Darrin
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated
Mon, 31 Jul 2006 17:35:56 remote, seen in
Matt Ratliff said:
In my .js file I add write a reference to the external .js file:

document.write('<script type="text/javascript" language="javascript" ^^^^^^^^^^^^^^^^^^^^ 1
src="http:/somedomain/javascript/standard.js"></script>')
^\ 2

1 - Deprecated/superfluous
2 - Desirable
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top