I want to be able to define a custom onerror event that detects an
attempt to call a known function and load a file if it's not already
loaded and re-call the function. The only problem is that any
triggering of the onerror event stops execution of the script block in
question. Is there a workaround for this?
Here's an example of what I'm trying to accomplish:
=============== =============== =============== =====
<!-- begin test.html -->
<html>
<head>
<title></title>
<script type="text/javascript">
function customerror(msg , url, line)
{
if (msg == 'customfunction is not defined')
{
var js = document.create Element("script ");
js.src = 'customfunction .js';
js.type="text/javascript";
document.getEle mentsByTagName( "head")[0].appendChild(js );
}
return(true);
}
window.onerror = customerror;
alert('before error');
customfunction( );
alert('after error'); // the error above prevents this line from
executing
</script>
</head>
<body>
some html text
<script type="text/javascript">
alert('inside body');
</script>
</body>
</html>
<!-- end test.html -->
=============== =============== =============== =====
/* begin customfunction. js */
alert('customfu nction.js loaded');
function customfunction( )
{
alert('inside customfunction' );
}
/* end customfunction. js */
=============== =============== =============== =====
Aside from the missing feature detection, forwarded function
parameters, etc (this is just a prototype), the problem is that any
code executed after the invalid function call is made gets skipped. It
seems that any error kills the rest of the script block ... is there a
way around this without putting every line of code on its own script
block?
Oh yeah, putting each command in its own script block seems to work
around this "problem", but that seems like a terrible solution. I know
I could just create a loading wrapper for all of the functions in
question, but I wanted something more transparent than that.
-tm 3 2242
Tobius wrote: I want to be able to define a custom onerror event that detects an attempt to call a known function and load a file if it's not already loaded and re-call the function. The only problem is that any triggering of the onerror event stops execution of the script block in question. Is there a workaround for this?
I am afraid no. Besides, `onerror' is proprietary.
Here's an example of what I'm trying to accomplish: [...] function customerror(msg , url, line) { if (msg == 'customfunction is not defined') { var js = document.create Element("script "); js.src = 'customfunction .js'; js.type="text/javascript"; document.getEle mentsByTagName( "head")[0].appendChild(js ); }
Here you would want to assign `null' to `window.onerror '.
return(true); }
window.onerror = customerror;
alert('before error'); customfunction( ); alert('after error'); // the error above prevents this line from executing
You are doing this the wrong way. Instead of waiting that the error
occurs, you should do a feature test so that no error can occur.
if (typeof ... != "function")
{
loadScript(...) ;
}
if (typeof ... == "function")
{
... ...(...) ...
}
That said, loading script code this way is recommended against, because
it is known to be unreliable and not backed up by any standard.
HTH
PointedEars
Are there any modern browsers that don't support onerror? My targeted
browser support list is:
Internet Explorer 5.5+
Mozilla Firebird 1.05+
Safari 1.2+
Have you witnessed this event fail to work in any of those browsers?
How does setting "window.one rror = null" help me with this exercise?
Does this allow me to detect an undefined function call in some way of
which I'm failing to see?
Anyhow, the whole point of this exercise is to be able to dynamically
load a library function "as" it's needed instead of "in case" it's
needed. The purpose is to allow a javascript developer to have all of
their javascript libraries available to them on every site they develop
without requiring having to over-bloat their web pages or manually
include sub-sets of their libraries on individual pages. Have you ever
seen anyone doing anything like this?
Tobius wrote: Are there any modern browsers that don't support onerror?
Possible.
My targeted browser support list is:
Internet Explorer 5.5+ Mozilla Firebird 1.05+
Maybe you have not heard yet: The browser is called Firefox since its
version 0.8 (Royal Oak, released Febrary 9 2004 CE). There has never
been "Mozilla Firebird 1.05".
Safari 1.2+
Have you witnessed this event fail to work in any of those browsers?
Depends on what you mean by that. That following code is not executed
even though `true' is returned in Firefox 1.5.0.1/Linux could be considered
a failure, because in Mozilla/4.0 (NN 4.x), where this error-handling
approach originates from, it did not happen the last time I checked.
But then, IIRC I never tried to work around ReferenceErrors with it.
ReferenceErrors are known to be somewhat special regarding error/exception
handling. Search the archives.
How does setting "window.one rror = null" help me with this exercise?
It prevents that the error-handling function is called again and again,
even from within the error-handling function. Maybe that helps. So
probably this should be even the first statement within that function.
Does this allow me to detect an undefined function call in some way of which I'm failing to see?
Perhaps. However, with your targeted environments, if you insist risking
the error and handling it later (what I recommended against and provided
a viable alternative for, which apparently you have ignored kindly), you
should use try..catch instead. I use the `onerror' event handler iff I
want to provide for graceful degradation for not backwards-compatible
language features (particularly for NN4), such as try..catch.
Anyhow, the whole point of this exercise is to be able to dynamically load a library function "as" it's needed instead of "in case" it's needed. The purpose is to allow a javascript developer to have all of their javascript libraries available to them on every site they develop without requiring having to over-bloat their web pages or manually include sub-sets of their libraries on individual pages. Have you ever seen anyone doing anything like this?
I have, and I have commented on it already, here.
PointedEars This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Robert Oschler |
last post by:
If I set window.onerror to an error handler I've created, I don't see the
browser error dialogs anymore but I don't see the alert() messages in my
error handler pop up either. Can someone tell me what I am doing wrong?
Here's the test doc I'm using:
=========== BEGIN TEST DOC ===================
<HTML>
<TITLE> OnError Test </TITLE>
<HEAD>
|
by: bjarthur |
last post by:
i have (see below) what i think is a fairly simple algorithm, but yet
it doesn't work. given a directory with consecutively numbered jpeg
files (1.jpg, 2.jpg, 3.jpg...), it is designed to count how many files
there are using a binary search. it uses the onload and onerror event
handlers of the image object to see if the files successfully loaded or
not. testing on a macintosh (os x 10.3.8) with a directory of 39
files, IE 5.2 and...
|
by: Doug O'Leary |
last post by:
Hey;
I'm completely new to javascript and am slowly working my way through
the O'Reilly's Javascript, the Definitive Guide. One of the examples
is supposed to pop up an alert box if there's a javascript error. I
typed in the code pretty much as documented but it didn't work. In
an attempt to troubleshoot, I simplified the thing but it's still
not working. The html and javascript code is posted below. Can
someone tell me what I...
|
by: Tee |
last post by:
what's the differences between "Overrides Sub OnError" and "Sub Page_Error"
?
|
by: Pete Verdon |
last post by:
I'm working on a fairly sizeable javascript application. I recently
added some error-handling to it, using window.onerror to catch them.
This sometimes works and sometimes doesn't; if I introduce a deliberate
mistake "near the top" of the system then it's trapped and handled
properly, but there's lots of code where mistakes only show up in my
Firebug console.
My first thought is that, since a lot of the work happens in callbacks
after...
| |
by: qwertycat |
last post by:
Is it possible to execute programs in a PHP script without waiting for
the output and successfully ending the PHP script without ending the
external program too?
|
by: Baladin |
last post by:
Hi
I've got a form for Data Capture with loads of Text boxs with the same name, except with a different number at the end, oh and im using VB 2005
i.e.
txtName1 txtDOB1
txtName2 txtDOB2
... ...
|
by: test9991014 |
last post by:
Hi,
I gather that Javascript standard function names are case sensitive
and they follow the old Smalltalk manner of applying case e.g.
thisName,
however I am curious, I see "onerror" mentioned on some web pages
which seems to contradict the standard. Or is it actually onError?
Thanks.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |