Question

which javascript command can be interupted by event handlers?

Asked by: intellias_net

Which commands can be interrupted by event handlers?
There are some javascript commands that can be interupted allowing other javascript procedures to be called (e.g. event handlers).  
For example insertBefore can trigger a resize event following the insertBefore command.
I was not aware that a procedure can be interrupted for events and expected the interrupt to be handled after the procedure returned to windows idle.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-10 at 10:43:46ID24722244
Topics

JavaScript

,

Internet Explorer Web Browser

Participating Experts
5
Points
250
Comments
36

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. How do set up a Keyboard Interupt
    I would like to set up a Keyboard Interupt using interupt 9 and reading the value from port 60h so that I can detect which key is being pressed.
  2. interupt thread
    Hi all I have class which extends Thread (I use this inheritance to have the interupt capability only, I don't use the run() method) : class A extends Thread { void stop() { this.interupt(); } func void doSomting() {...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: wilq32Posted on 2009-10-02 at 00:33:04ID: 25475759

There is no such a thing like interrupting JavaScript. Basically JavaScript is singlethread - that means that if you want to fire any new function, previous one has to stop. Easiest way to see that is to have a while(1) loop and try to fire a event. Your browse will hang out probably but this is only to visualize. As you noticed insertBefore can trigger some kind of event but this will be fired after whole function that adds this to document, and all actual stack of functions finish..

 

by: BadotzPosted on 2009-10-02 at 06:21:42ID: 25477568

The best you can hope for is to have a function run periodically via "setInterval".

I'm not sure what would happen during the infinite loop (as suggested by wilq32), but it would be interesting to test it.

 

by: HonorGodPosted on 2009-10-02 at 08:23:17ID: 25478790

Most current browsers will detect an infinite loop and signal (alert the user) that a script is "busy", and give you an opportunity to terminate the script.

 

by: BadotzPosted on 2009-10-02 at 08:36:22ID: 25478910

Right, but will a function invoked via "setInterval" interrupt while the infinite loop is doing it's thing doing it's thing doing it's thing...?

 

by: intellias_netPosted on 2009-10-02 at 08:56:24ID: 25479120

txs for all your comments.  However some of you are dead wrong.  There are some commands that can be interrupted, no matter what the spec says and I have sample code to prove it.  In particular insertBefore; and, it can be interrupted following the command to handle a resize event.  

I too thought javascript was single threaded so I was surprise also.  Nevertheless thank you for your support.

 

by: BadotzPosted on 2009-10-02 at 09:15:20ID: 25479333

If your issues was not resolved, why did you close the question? And why did you not say something after your initial post?

Awarding a "C" grade is a sure way to rankle us experts. Kind of like biting the hand that feeds you?

For future reference, please list all of the commands that can be interrupted, and show an example illustrating this.

 

by: wilq32Posted on 2009-10-02 at 09:16:02ID: 25479342

Could you please provide some test case ? Im also interested in this "hidden" feature of JavaScript language that I never encounter

 

by: intellias_netPosted on 2009-10-05 at 05:22:02ID: 25494477

When I have some down time I'll provide a sample.
Didn't mean to "rankle" anyone or shoot anyone in the foot.  
I have a case where I log the events as they come in and found  that the resize event was handled just after the inserBefore and before the following log even.

thanks for your support.  

 

by: mplungjanPosted on 2009-10-05 at 22:09:25ID: 25502008

Also interested in example

 

by: BadotzPosted on 2009-10-08 at 14:04:13ID: 25530068

Again, as you were instructed to do, please list all of the commands that can be interrupted, and show an example illustrating this.

 

by: intellias_netPosted on 2009-10-08 at 14:10:26ID: 25530128

So far there are two commands that will allow a procedure to be interrupted.
document.writeln
and insertBefore.
document.writeln is the easiest to confirm, just create an onunload event for the body and it will fire and code execute after docuement.writeln.  After the event is handled the procedure will resume following document.writeln.

I do not requre any more responses to this issue,  thanks to all.

 

by: wilq32Posted on 2009-10-08 at 14:12:51ID: 25530151

Please provide simplest test case - im really curious

 

by: BadotzPosted on 2009-10-08 at 14:17:21ID: 25530190

>>im really curious  (sic)

We *ALL* are curious to see the code.

 

by: BadotzPosted on 2009-10-08 at 14:19:52ID: 25530213

I want to see a working example of this. intellias_net opened this door, by gum, and I'm not willing to let him close it so easily.

 

by: intellias_netPosted on 2009-10-08 at 14:22:19ID: 25530235

OK OK, i'll send it on monday.

 

by: mplungjanPosted on 2009-10-08 at 23:25:09ID: 25532691

 

by: b0lsc0ttPosted on 2009-10-09 at 11:10:43ID: 25537352

@mplungjan,
Thanks!  That was what I was referring to in the first paragraph of http:#a25499347 .  I may not have worded it well and am glad you posted the details but can't see that it would do what the "insertBefore command" the Asker describes.  That was why I, like all of us others it seems, are so curious for some details.  We will see what Monday brings. :)

bol

 

by: BadotzPosted on 2009-10-09 at 11:17:05ID: 25537416

I don't like Mondays,
I don't like Mondays.
I don't like Mondays
I want to ...

 

by: intellias_netPosted on 2009-10-13 at 07:34:21ID: 31627206

Beside being wrong, some of the answers had nothing to do with the question

 

by: intellias_netPosted on 2009-10-13 at 11:10:29ID: 25562551

Here is a sample that show that onload will fire and execute code before onclick event is finished.  
Onresize works too.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    <script>
    function formMain()
    {
       	var	vCode	=	"<html><head></head><body onunload='parent.onunloadBody()'><form name=form2 id=form2><table>"
		+ "<tr><td align='center' colspan=2><button name=but onclick='parent.onclickButton()'>Unload</button></td></tr>"
		+ "</table></form></body></html>"
        main.document.writeln(vCode)
        main.document.close()
         
        return
    }
    var whoisfirst=""
    
    function onclickButton()
    {
        debugger
        formMain()
        if (!whoisfirst)
            whoisfirst="onclickButton"
        return
    }
    function onunloadBody()
    {
        if (!whoisfirst)
            whoisfirst="onunloadBody"
        alert(whoisfirst)
    }
    </script>
</head>
<frameset name="mainframeset" ROWS="100%,*" frameborder="no" border="0" marginwidth="0" marginheight="0" onload='formMain(true)'>
	<frame name="main" frameborder="yes" border="1" marginwidth="0" marginheight="0">
</frameset>
 
</html>
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:

Select allOpen in new window

 

by: BadotzPosted on 2009-10-13 at 11:35:06ID: 25562792

Is anyone else overwhelmed with this?

 

by: wilq32Posted on 2009-10-13 at 14:20:29ID: 25564878

I dont see any problems in code and seeing anything breaking code, but maybe I'm blind. Please correct me if im wrong I will try to follow application flow:

1. First of all we got a frameset caling a function formMain().
2. formMain basically creates a form, then writes to a document then closes it.
3. Closing function calls a onunloadBody function that do this:

sets a whoisfirst global variable to a "onunloadBody" if its not set then alerts it.


Then every new instance of a onclickButton does create form again and closes it, but global variable is already set so no new assignement occures.

I'm just wondering why there is a button still if you close a document there - any explanation for that from experts?

Anyway there is a small problem with context of a whoisfirst variable. I tested this on chrome and got diffrent results so there might be a reference to a window.whoisfirst variable that would be erased every time we creating new form... However when I run this in firefox I did not found out any "code breaking" behaviour using or not a debugger - do I miss something ?

 

by: wilq32Posted on 2009-10-13 at 14:21:44ID: 25564897

" that would be erased every time we creating new form..." - of course I mean new document with form :)

 

by: BadotzPosted on 2009-10-13 at 14:44:52ID: 25565111

I don't believe so. I ran the page but I have no idea how or where the "interrupt" occurs. Setting a variable from within a function hardly qualifies.

Perhaps intellias_net can give his thoughts and/or reasoning behind this example?

 

by: intellias_netPosted on 2009-10-14 at 10:29:55ID: 25572924

Thank you for your interest.
To the best of my abliity, the previous example works as follows:
1. onunload fires when a form is unloaded
2. main.document.close() does not fire off unload
3. remove 'debugger' if you like, I tested it without it.

formMain builds a form with in the frame named 'main' via commands:
main.document.writeln()
main.document.close()
When the form is displayed there is a button "Unload"
Pressing this button initiates a call to 'onclickButton'
onclickButton which repeats the previous operation and writes over the form with a new one.
Although this is redundant it serves well as the sample code.
Writing over the old form will cause 'onunload' event to fire.
If javascript was not interuptable then after the form is built it will return to onclickButton and
set 'whoisfirst' to 'onclickButton'
whoisfirst is a global and can only be set once (test for set before setting).
However if javascript is interupted and the onunload fires before returning to 'onclickButton'  then 'whoisfirst' global would be set to 'onunloadBody' and an alert initiated.  And the onclickButton won't be able to set 'whoisfirst'.
The later case is what happens.

A simular condition will happen for insertBefore with the 'onresize' event.

I welcome your feedback or criticism on any 'holes' in my logic.

 

by: wilq32Posted on 2009-10-14 at 11:16:48ID: 25573391

So first of all can you tell me what browser you test that on?

I test it on firefox 3.5, chrome, IE 7.0  and all of those browsers return diffrent results and does not refeers to language specyfication.

I prepare some more realiable (hopefully) test to run with, because alerts give some strange results (I assume because of some optimalisation method used over firefox).

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    <script>
	function log(text){
	    logFrame.document.writeln(text+"<br>");
	}
    function formMain()
    {
		log("formMain");
        var     vCode   =       "<html><head></head><body onunload='parent.onunloadBody()'><form name=form2 id=form2><table>"
                + "<tr><td align='center' colspan=2><button name=but onclick='parent.onclickButton()'>Unload</button></td></tr>"
                + "</table></form></body></html>"
        main.document.writeln(vCode);
        main.document.close()
         
        return
    }
    var whoisfirst=""
    
    function onclickButton()
    {
        //debugger
		log("onclick1");
        formMain()
		log("onclick2");
        if (!whoisfirst)
            whoisfirst="onclickButton"
        return
    }
    function onunloadBody()
    {
	    log("onunload");
        if (!whoisfirst)
            whoisfirst="onunloadBody"
        //alert(whoisfirst)
    }
 
    </script> 
</head>
<frameset name="mainframeset" ROWS="50%,*" frameborder="no" border="0" marginwidth="0" marginheight="0" onload="formMain()">
        <frame name="main" frameborder="yes" border="1" marginwidth="0" marginheight="0">
		<frame name="logFrame" frameborder="yes" border="1" marginwidth="0" marginheight="0">
</frameset>
 
 
</html>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:

Select allOpen in new window

 

by: intellias_netPosted on 2009-10-14 at 11:42:40ID: 25573668

Thanks for the warning, that was helpful.
I'm using IE 6.0 and have not tested it on 7.0 or firefox.  However, at the worst case by assuming this is posible, I will be protected either way.

 

by: wilq32Posted on 2009-10-14 at 12:06:19ID: 25573918

To answer your question:

"which javascript command can be interupted by event handlers?"

- From language definition - there should be no commands,
- this may vary depends on browser and javascript engine used (basically what is in IE JScript implementation is not a standardized  JavaScript that you might ask for - or maybe you dont ask for any standards there ;>)

 

by: intellias_netPosted on 2009-10-14 at 12:50:23ID: 25574380

Hmm standards?  didn't look there.  Isn't that set up in <DOCTYPE

 

by: wilq32Posted on 2009-10-14 at 13:12:23ID: 25574616

it just apply to a HTML standards, not a JavaScript engine :)

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...