Can't get external javascript file to work

sozk

New Member
Hi,

I'm trying to add an external javascript file to my code but so far am not having any luck getting it working. Any help would be appreciated!

The javascript file just contains a simple function with an alert('hello world').

I add the <script> tag to my webspeed file between the <head> tags:
{&out} '<script language="javascript" type="text/javascript" src="/js/hellow.js"></script>'.

When this function is called within the html code, it just returns a javascript error 'object not found', so it is not finding the hello world function.

however, when I place the javascript itself within the <script> tags in my webspeed file, the javascript works fine when it is called from the html code.

{&out} '<script language="javascript" type="text/javascript" >
function hw()~{
alert("hello world");
~}
<script>'.

I've placed the javascript file in the same directory where my other source code is run from and the web server is on my local machine.

Is there any reason why I can't get the external javascript file to work? Is there any other settings on my machine I should look at. I've already ticked the IE property to 'Run Active Content on my PC'.

Again any help would be greatly appreciated as have been banging my head off a wall over this!
 
I've placed the javascript file in the same directory where my other source code is run from and the web server is on my local machine.

JavaScript is run from within the html page. So its path should be local to document root in your webenvironment. In you are using apache then the javascript source file should be in /var/www/html/js on linux or C:\Program Files\Apache Group\Apache2\htdocs\js (for a default install on windows).

remember that the progress code does nothing else then generate web pages which are then transported to the webserver which handles the requests.

Casper.
 
Thank you so much for your quick reply. It's much appreciated and gave me some clues to follow. However I still can't get it to work.

I'm actually using Windows IIS webserver. I've added the js directory as a virtual directory to the IIS server, but am still having no luck. I've also tried putting the js directory into the c:\inetpub\wwwroot default directory without any luck either.

still beating my head off the wall!
 
actually have just figured it out!

i added the 'js' virtual directory pointing at the location of my source code under the default website in IIS. Then in the properties dialogue for this virtual js directory, i then had to go into 'configuration' and add the .js file extension to the application mappings. (you'd think microsoft would have added this to the default list!)

Anyhow thanks for your help and I hope this helps other people!
 
actually i need to correct the above. it wasn't adding the .js extension to the application mappings in IIS that fixed it. I deleted that .js extension from the mappins which relates to something else..

The problem was actually caused in <script> tags in the html. It objected to my having both the language = 'javascript' and the type ='text/javascript' attributes in the script tag. when i took out the language attribute, the external javascript files started to work without any issues.
 
Back
Top