Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Stop Javascript execution safely?

Reply
Thread Tools

Stop Javascript execution safely?

 
 
howa
Guest
Posts: n/a
 
      09-06-2007
Are there any method to stop the current JS execution on a page
safely, something like PHP's die() functuin ?

 
Reply With Quote
 
 
 
 
Erwin Moller
Guest
Posts: n/a
 
      09-06-2007
howa wrote:
> Are there any method to stop the current JS execution on a page
> safely, something like PHP's die() functuin ?
>


Hi,

From Javascript itself on the page?
As far as I know: No.

You could of course wrap every javascript-command and function in an
if-then block, checking if the command should run.

Why would you want such a thing in the first place?

Regards,
Erwin Moller
 
Reply With Quote
 
 
 
 
nas_bk@hotmail.com
Guest
Posts: n/a
 
      09-06-2007
exit(0);

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      09-06-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> exit(0);


troff


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
 
Reply With Quote
 
michael@greenquery.com
Guest
Posts: n/a
 
      09-07-2007
On 6 Sep., 19:12, howa <(E-Mail Removed)> wrote:
> Are there any method to stop the current JS execution on a page
> safely, something like PHP's die() functuin ?


Hi Howa,

Yes javascript does come with error handling, and it work's just like
java.

try{
var myObj = document.missing.element;
} catch (e) {
alert('Error looking for document.missing.element\n' + e);
}

Hope it helps

//Michael

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      09-07-2007
(E-Mail Removed) wrote:
> On 6 Sep., 19:12, howa <(E-Mail Removed)> wrote:
>> Are there any method to stop the current JS execution on a page
>> safely, something like PHP's die() functuin ?

>
> [...]
> Yes javascript does come with error handling, and it work's just like
> java.


It doesn't. At least not everywhere.

> try{
> var myObj = document.missing.element;
> } catch (e) {
> alert('Error looking for document.missing.element\n' + e);


If would have been easier to display the value of e.message or a similar
property.

> }


That is falsely assuming error handling would be equivalent to stopping
execution with PHP's die(). To stop execution this way, one would have
to cause a run-time error deliberately, which is bad style, even in Java.
An example of a better way would be

var statements, foo = true;

try
{
statements;
if (foo) throw new Error("bar");
}
catch (e)
{
window.alert(e.message);
}

But one would have to rely on support for exceptions in either case here.

However, your reply indicates the very simple and fully compatible solution
to this actually minor problem: instead of stopping execution when a
condition applies, have the following code only executed if it doesn't.


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
private data stashed in local/global execution context of PyEval_EvalCode disappears down the execution stack sndive@gmail.com Python 9 11-14-2007 10:31 PM
How do I stop javascript execution? Ralphz Javascript 3 09-19-2007 10:31 AM
How do I stop the Webservice execution after certain amount of time? Jack Wright ASP .Net 2 05-28-2007 07:06 AM
Stop further execution in Page_Load Gopal Krish ASP .Net 2 10-25-2004 06:37 PM
oProxy.Timeout does not stop the WebService execution thread Jack Wright ASP .Net 1 02-22-2004 10:08 AM



Advertisments