T
Tobius
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.createElement("script");
js.src = 'customfunction.js';
js.type="text/javascript";
document.getElementsByTagName("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('customfunction.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
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.createElement("script");
js.src = 'customfunction.js';
js.type="text/javascript";
document.getElementsByTagName("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('customfunction.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