473,387 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

SRC= and missing .JS file

Hi,

Could not find the answer neither in FAQs not on the Web...

On many javaScript 'tips' sites they say that do warn the user
regarding missing .JS file one should do the following:
<html>
<head>
....
<script src="ABC.js" ...>
alert("Error! Included JS file not found ...");
</script>
</head>
....

But it does NOT work neither in my IE 6 nor in my Mozilla 1.6 -
no alert when the .JS file does not exist.

http://www.htmlhelp.com/reference/ht...al/script.html

says,
"When the SRC attribute is used, the embedded script is ignored."
which does not touch the case when .JS not found
(or does it? Ignored _always_?)

So how to tell the user that .JS to be included was not found?

--
Regards,
Paul
http://KBD.da.ru - was possible to develop only because
of the great article at
http://www.faqts.com/knowledge_base/view.phtml/aid/1661
Jul 23 '05 #1
13 2276
In article <36*************************@posting.google.com> , Paul
Gorodyansky <pa*****@compuserve.com> wrote:
Hi,

Could not find the answer neither in FAQs not on the Web...

On many javaScript 'tips' sites they say that do warn the user
regarding missing .JS file one should do the following:
<html>
<head>
...
<script src="ABC.js" ...>
alert("Error! Included JS file not found ...");
</script>
</head>
...

But it does NOT work neither in my IE 6 nor in my Mozilla 1.6 -
no alert when the .JS file does not exist.

http://www.htmlhelp.com/reference/ht...al/script.html

says,
"When the SRC attribute is used, the embedded script is ignored."
which does not touch the case when .JS not found
(or does it? Ignored _always_?)

So how to tell the user that .JS to be included was not found?


I've been experimenting with the following and it seems to work. In the
..js file put the following statement at the top.
var script111loaded = "true";

Now in the HTML put
<script type="text/javascript">
if (!script111loaded) {alert("script 111 not loaded")};
</script>

--
Dennis M. Marks
http://www.dcs-chico.com/~denmarks/
Replace domain.invalid with dcsi.net
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #2
Hi,

Dennis M. Marks wrote:
...
So how to tell the user that .JS to be included was not found?

I've been experimenting with the following and it seems to work. In the
.js file put the following statement at the top.
var script111loaded = "true";

Now in the HTML put
<script type="text/javascript">
if (!script111loaded) {alert("script 111 not loaded")};
</script>


Thanks, it works (though, I had to declare that variable
at the top of my _html_ text,too - otherwise _if_ did not
work - just has "undefined" error in JS Console, at least
in Mozilla 1.6).

--
Regards,
Paul
Jul 23 '05 #3
In article <c5*************@ID-25072.news.uni-berlin.de>, Paul
Gorodyansky <pa*****@compuserve.com> wrote:
Hi,

Dennis M. Marks wrote:
...
So how to tell the user that .JS to be included was not found?

I've been experimenting with the following and it seems to work. In the
.js file put the following statement at the top.
var script111loaded = "true";

Now in the HTML put
<script type="text/javascript">
if (!script111loaded) {alert("script 111 not loaded")};
</script>


Thanks, it works (though, I had to declare that variable
at the top of my _html_ text,too - otherwise _if_ did not
work - just has "undefined" error in JS Console, at least
in Mozilla 1.6).


I tested it in IE. I should have followed through with Netscape.

Why doesn't a test like "if (document.getElementById) {xxx}" give an
undefined error in some browsers, or does it?

--
Dennis M. Marks
http://www.dcs-chico.com/~denmarks/
Replace domain.invalid with dcsi.net
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #4
JRS: In article <36*************************@posting.google.com> , seen
in news:comp.lang.javascript, Paul Gorodyansky <pa*****@compuserve.com>
posted at Fri, 9 Apr 2004 15:54:16 :
Could not find the answer neither in FAQs not on the Web...
<URL:http://www.merlyn.demon.co.uk/js-nclds.htm> now answers that.
So how to tell the user that .JS to be included was not found?


I test for the existence of a variable declared in it.

I don't know about putting material here --------+
V
<script type="text/javascript" src="include1.js"> </script>

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #5
JRS: In article <09*************************@domain.invalid>, seen in
news:comp.lang.javascript, Dennis M. Marks <de******@domain.invalid>
posted at Fri, 9 Apr 2004 17:36:54 :

I've been experimenting with the following and it seems to work. In the
.js file put the following statement at the top.
var script111loaded = "true";

Now in the HTML put
<script type="text/javascript">
if (!script111loaded) {alert("script 111 not loaded")};
</script>

Why did you choose to assign a string to script111loaded ?
<rhetorical> How about "false", "banana", or just 1 ?

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #6
Dr John Stockton wrote:
if (!script111loaded) {alert("script 111 not loaded")};

if(!this.script111loaded) //...
Why did you choose to assign a string to script111loaded ?
<rhetorical> How about "false", "banana", or just 1 ?


Well, any non-empty string would technically type-convert to true,
though I question the semantic value of "banana" for maintenance
purposes... :-)

As you suggest, using a boolean instead of a string would definitely be
a good idea!
Jul 23 '05 #7
In article <wa**************@merlyn.demon.co.uk>, Dr John Stockton
<sp**@merlyn.demon.co.uk> wrote:
JRS: In article <09*************************@domain.invalid>, seen in
news:comp.lang.javascript, Dennis M. Marks <de******@domain.invalid>
posted at Fri, 9 Apr 2004 17:36:54 :

I've been experimenting with the following and it seems to work. In the
.js file put the following statement at the top.
var script111loaded = "true";

Now in the HTML put
<script type="text/javascript">
if (!script111loaded) {alert("script 111 not loaded")};
</script>

Why did you choose to assign a string to script111loaded ?
<rhetorical> How about "false", "banana", or just 1 ?


True should not have had quotes around it. That was ANOTHER mistake I
made.

I don't understand your RHETORICAL response unless it is the quotes.
Any value would be ok but true is simpler for the IF.

--
Dennis M. Marks
http://www.dcs-chico.com/~denmarks/
Replace domain.invalid with dcsi.net
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #8
Dr John Stockton wrote:
Paul Gorodyansky wrote:
So how to tell the user that .JS to be included was not found?

I can understand why a script may care that a file on which it is
dependent has not loaded, but I don't see much point in telling the user
in most cases as there is not going to be a great deal that they can do
about it (assuming that they understand the role of a JS file in the
first place).
I test for the existence of a variable declared in it.

I don't know about putting material here --------+
V
<script type="text/javascript" src="include1.js"> </script>


One of the problems with this is how the server reacts to its inability
to find the file. A suitable HTTP error response should tell the browser
that something is up, but many servers are configured to send custom
HTML pages that announce the error to the user but might still give the
browser the impression that the resource that was requested has been
returned. And an HTML file sent in the pace of a JS file will produce a
syntax error, but not necessarily result in the fall-back to using the
contents of the script element.

Richard.
Jul 23 '05 #9
Hello!

Richard Cornford wrote:
One of the problems with this is how the server reacts to its inability
to find the file. A suitable HTTP error response should tell the browser
that something is up, but many servers are configured to send custom
HTML pages that announce the error to the user but might still give the
browser the impression that the resource that was requested has been
returned. And an HTML file sent in the pace of a JS file will produce a
syntax error, but not necessarily result in the fall-back to using the
contents of the script element.

Richard.


it was exactly my reason to post the question here - with
my ISP - CompuServe - *nothing* happens - page loads,... -
no error of any kind, so a user is just
confused why the expected functionality failing - _I_
need to explain the user why :)

BTW, obviously I used a _Boolean_ variable after getting
a response here :)

--
Regards,
Paul

Jul 23 '05 #10
On Sat, 10 Apr 2004 08:10:47 -0700, Dennis M. Marks
<de******@domain.invalid> wrote:

[snip]
Why doesn't a test like "if (document.getElementById) {xxx}" give an
undefined error in some browsers, or does it?


In Opera, Mozilla and IE, it does. It probably does in every browser.

If the OP wants to avoid getting "undefined" errors, you could do

if( 'undefined' == typeof scriptXXXloaded ) {
// script XXX is not loaded
}

and declare scriptXXXloaded somewhere in the script

var scriptXXXloaded = true;

This will avoid the need to declare the variable in the containing HTML
file. The value of the variable itself is irrelevant, just so long as it's
not undefined.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #11
Michael Winter wrote:
On Sat, 10 Apr 2004 08:10:47 -0700, Dennis M. Marks
<de******@domain.invalid> wrote:

[snip]
Why doesn't a test like "if (document.getElementById) {xxx}" give an
undefined error in some browsers, or does it?


In Opera, Mozilla and IE, it does. It probably does in every browser.

<snip>

"if (document.getElementById) {xxx}" - will only produce an undefined
error if - document - is undefined (and a different error if null).
Reading a non-existent property form an object returns an undefined
value, which happily type-converts to boolean false for the expression
of the - if - statement (no errors result).

The OP's problem with - if(!script111loaded) { ... }; - is that the
scope chain resolution of the identifier for an undeclared (and
unassigned) global variable has a null base object on the returned
Reference, and the subsequent use of that Reference with the internal -
GetValue - function is required to throw an exception when the base
object is null.

The typeof operator avoids the problem as it has special handling when a
Reference has a null base object, but a property accessor, where the
identifiers before the property name refer to existing objects, will
never return a Reference with a null base object (so it will never throw
an exception when used with - GetValue).

Richard.
Jul 23 '05 #12
On Thu, 15 Apr 2004 17:54:51 +0100, Richard Cornford
<Ri*****@litotes.demon.co.uk> wrote:
Michael Winter wrote:
On Sat, 10 Apr 2004 08:10:47 -0700, Dennis M. Marks
<de******@domain.invalid> wrote:

[snip]
Why doesn't a test like "if (document.getElementById) {xxx}" give an
undefined error in some browsers, or does it?


In Opera, Mozilla and IE, it does. It probably does in every browser.


"if (document.getElementById) {xxx}" - will only produce an undefined
error if - document - is undefined (and a different error if null).
Reading a non-existent property form an object returns an undefined
value, which happily type-converts to boolean false for the expression
of the - if - statement (no errors result).


[snip]

The problem isn't with the conditional expression, it is with xxx itself.
I would guess that as xxx hasn't been previously defined, and isn't part
of an assignment (where the variable would become global), the interpreter
is trying to evaluate something that obviously doesn't exist, hence the
undefined error.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #13
Michael Winter wrote:
Richard Cornford wrote:
Michael Winter wrote:
Dennis M. Marks wrote:
Why doesn't a test like "if (document.getElementById) {xxx}" give
an undefined error in some browsers, or does it?

In Opera, Mozilla and IE, it does. It probably does in every
browser.
<snip> The problem isn't with the conditional expression, it is with xxx
itself. I would guess that as xxx hasn't been previously defined, and
isn't part of an assignment (where the variable would become global),
the interpreter is trying to evaluate something that obviously
doesn't exist, hence the undefined error.


Ah, you are being unusually pedantic. I took the - xxx - as standing in
for some unspecified block of code to be executed if -
document.getElementById - type-converted to true. I usually use - ... -
in that context, which will also predictably error if actually executed.

Richard.
Jul 23 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: bhennon | last post by:
Hey all, I have a small php script that calls a random image at the following page. http://www.2006ymcanationals.com/random.php IT WORKS IF I go directly to the above link. I am trying to...
1
by: j erickson | last post by:
with the following xsl and xml file, the display of the gif file with the <image/url> tag works. However, the gif file in the <description> tag using the name attribute "src" won't make the correct...
2
by: wylbur37 | last post by:
I normally use Mozilla 1.4 on Windows XP Pro. As I was developing some test webpages, I discovered that the SRC parameter doesn't seem to work when a path is used with the filename. In one...
8
by: dstefani | last post by:
Hello, I was wondering if you can get the info from the query string in a server-side javascript tag? Here's what I'm trying to do In the head of page A ....
23
by: Loony | last post by:
I have got a code like this in HTML section in ASP file which includes javascript file! The script works under MS IE but doesn't with Firefox! Can anybody tell me what is wrong? <HTML>...
12
by: A.M | last post by:
Hi, Using VS.NET 2003, If i use SRC page attribute instead of CodeBehind, do i still have intelisence and generally IDE support for that? Thanks, Ali
1
by: Michael | last post by:
Hello, I'm trying to implement sample I found on page templates, so I do not have to maintain "<html><head>..." on all my documents. But don't let that confuse you, this is an inheritance...
3
by: kansaschuck | last post by:
Ok... Let me start over since I had miss labeled the other question and it ended up in phpland and I failed to follow the posting rules. Sorry, here's a rework. (hey... I just saw the html code...
5
by: enaz | last post by:
Ok, so, this is my first post, if there is any info i am leaving out please tell me this is the function: function mouseOver(c) { alert(c); <!-- just for debugging--> if (c.src ==...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.