[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

executing a script in a separate file

Jay Braun

8/25/2015 6:45:00 PM

I have a web page that originally had embedded JavaScript within a script section, and it worked fine when served up with a simple http server.

I now want to put my JavaScript, which manipulates SVG elements, in separate files, and as a first try, I put it all in a singe .js file:

<!DOCTYPE html>
<meta charset="UTF-8">
<title>Some Graphics With SVG</title>
<head>
<meta http-equiv="refresh" content="5">
<style>
#svgContainer {
width: 2188px;
height: 1312px;
background-color: "white";
}
</style>
<script src="all.js"></script>
</head>
<body onload="resagui()">
<div id="svgContainer"></div>
</body>

I should note that the JavaScript function resagui appears at the top of all.js:

function resagui() {
...
}
Everything works great when I test this locally and view the page with file:///... from my browser. But when I try http://ipaddress:port it does not work. (A simple server application serves up the file index.html).

I know that this is not a network issue, as the html file with embedded JavaScript works fine when I try http://ipaddress:port

My Firefox browser console provides two errors:

SyntaxError: expected expression, got '<' and ReferenceError: resagui is not defined

The html looks well formed, and there is no '<' character in my .js file.

*** Please note that this is not a website per se. I have an application that generates and updates SVG descriptions of objects in JavaScript, and is attempting to specify, as the "URL" of the src attribute, a files in the same directory. Maybe this is where I am going wrong.

Thanks for any insight you can provide.

Jay
3 Answers

ram

8/25/2015 7:01:00 PM

0

Jay Braun <lyngwyst@gmail.com> writes:
>Everything works great when I test this locally and view the
>page with file:///... from my browser. But when I try
>http://ipaddress:port it does not work. (A simple server
>application serves up the file index.html).

It is possible that the server also serves »index.html«
when »all.js« is requested.

You could inspect the response you get when you manually
request »all.js«, possibly using a URI like

http://ipaddress:port/all.js

.

>SyntaxError: expected expression, got '<' and ReferenceError: resagui is not defined
>The html looks well formed, and there is no '<' character in my .js file.

It could hint at an HTML file being delivered when the
JavaScript file was requested.

Jay Braun

8/25/2015 7:47:00 PM

0

Got this to work when I switched from the following 1-line webserver:

while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; cat index.html; } | nc -l 8081; done

to:

python -m SimpleHTTPServer 8081

Hans-Georg Michna

8/26/2015 7:36:00 AM

0

On Tue, 25 Aug 2015 11:44:55 -0700 (PDT), Jay Braun wrote:

><!DOCTYPE html>
><meta charset="UTF-8">
><title>Some Graphics With SVG</title>
><head>
><meta http-equiv="refresh" content="5">
> <style>
> #svgContainer {
> width: 2188px;
> height: 1312px;
> background-color: "white";
> }
> </style>
><script src="all.js"></script>
></head>
><body onload="resagui()">
> <div id="svgContainer"></div>
></body>

title outside head?

Hans-Georg