IE7 script madness

Ever seen this guy?

Stop running this script dialog in IE7

I’m writing a piece on Javascript. In the new world of AJAX, web applications may run large amounts of client-side code in the browser. I’m having a look at performance issues, so I wrote some code that does some processing in a tight loop and tested it in IE7, FireFox 2.0 and Flash 9.

Getting timings was difficult, because IE7 pops up this “Stop running this script” dialog when my code is running. Nor will it let go. You click “No”, and 1 second later the dialog pops up again. And again. And again.

I’ve trawled through the IE7 options looking for a way to switch this thing off, but cannot find one. I’m hoping I’ve missed it, or that there is a secret registry key I can change, because it is really annoying.

I don’t understand why there is no option for ”don’t ask me again”, or “allow long-running scripts at this site”. After all, this scenario is going to get increasingly common. Neither FireFox nor Flash suffers from this problem.

I appreciate that IE7 is trying to be helpful here. There is though a fine line between helpful and annoying. Without any obvious way to prevent it, this falls in the latter category.

That said, I did find a way to get my timings, because of my experience with the htmleditor.  If you host Mshtml in an application, you can implement the COM interface IDocHostShowUI. This has a ShowMessage function which IE calls when it wants to show a dialog. This enables you to catch the over-helpful “stop this script” message and not show it.

Unfortunately this solution isn’t something users can easily apply. It requires creating your own customized version of IE. There must be some easier way and I look forward to learning what it is.

One last comment: why does Microsoft still come up with poorly thought-out UI elements like this? It is easy to think of better ways than a brutal modal dialog. How about a “stop script” toolbar button that appears only when scripts are taking too long or grabbing too much CPU?

Update

FireFox does exactly the same thing, also with a modal dialog, “A script on this page may be busy” …

Still, two benefits to FireFox. First, the timeout is set to a more reasonable 10 seconds. Second, you can easily amend it. Navigate to about:config. Find the entry dom.max_script_run_time. Change it from 10 to whatever you like. 

Further update

A comment has pointed me to this knowledgebase article.

Here’s the fix:

  1. Using a Registry Editor such as Regedt32.exe, open this key:
    HKEY_CURRENT_USER\Software\Microsoft\InternetExplorer\Styles

    Note If the Styles key is not present, create a new key that is called Styles.

  2. Create a new DWORD value called “MaxScriptStatements” under this key and set the value to the desired number of script statements.

    By default the key doesn’t exist. If the key has not been added, Internet Explorer 4 defaults to 5,000,000 statements executed as the trigger for the time-out dialog box.

Technorati tags: , , ,

VN:F [1.9.18_1163]
Rate this post
Rating: 10.0/10 (1 vote cast)
IE7 script madness, 10.0 out of 10 based on 1 rating

Related posts:

  1. More RSS madness from Microsoft – this time it’s Live Mail
  2. Windows Media Center madness
  3. Microsoft’s BPOS password madness driving users to Google Apps
  4. The new Google Chrome browser: a bad day for Firefox
  5. Internet Explorer no longer the de facto Web standard

11 comments to IE7 script madness

  • There’s a registry key you can set that controls the number of statements that are executed before the dialog pops up.

    See http://support.microsoft.com/default.aspx?scid=kb;en-us;175500

  • Tim

    Thanks Kristoffer – that’s just what I needed.

    That article didn’t turn up when I Googled for some reason.

    Tim

  • Flash actually does do this as well, and it is also through a pop-up. It is set to activate after 20 seconds of continuous processing within the same function. Code written in AS3 runs much faster within the new Flash virtual machine, so you are less likely to encounter the issue. With code targeting Flash 8 or earlier, this is not an uncommon problem when doing stuff such as loading large amounts of XML data to a data grid.

    It is not practical to set the values on users machines, so you have to find ways around it. One way is to break it up using setInterval() to avoid having one long loop, so that it calls the same function but gives it a different block of data to work on. Usually, if you have some script which is taking that long to execute, there is probably an issue with how you are doing things. For instance, one common error is to add rows to a grid one at a time, which results in one complete grid redraw for each row. Much more efficient is to add rows to an array first, then assign the entire array to your grid component.

    You can do code profiling with Firefox if you install the debugger extension (FireBug does this as well I believe). The profiler will tell you exactly how long each function is taking to run.

  • Tim

    > Usually, if you have some script which is
    > taking that long to execute, there is
    > probably an issue with how you are doing
    > things.

    I agree; running tests is perhaps the main exception.

    The IE case is worst, since the dialog pops up every second. However in all cases I reckon there should be a “don’t show again” option of some kind, valid perhaps for the current session only. That would give the user an easy solution for those cases where she does want the operation to complete.

    Incidentally I didn’t see this on Flash 9 because my test completed in less than 20 seconds :-)

    Tim

  • Bob C

    I, too am annoyed by this pop-up window. Ordinarily, I would ignore it, but, indeed, my computer does seem to be slowing down.

    So, I am trying to edit the HKEY_CURRENT_USER\Software\Microsoft\InternetExplorer\Styles key in the registry. What value do you use to the desired number of script statements, and how, exactly (menu items, specific key actions) do you do this.

    I feel like I am left high-and-dry when Micorsoft just says “Create a new DWORD value called “MaxScriptStatements” under this key and set the value to the desired number of script statements” and does not tell you how or what the value should be!

    What should the value be and how do I set it?

    HELP!

  • Tim

    > What should the value be and how do I set it?

    The article says that the value defaults to 5,000,000. So I guess, you set it to less than that if you want the popups more often, or more than that if you want the popups less often.

    Tim

  • I get this message after A few minutes on webshots no matter what type of pictures I am lookinf at. It eventually freezes up the Computer.

  • Brij

    today i found some weird thing when i was troubleshooting “Stop running this script” problem.
    and i am not ready to accept the fact that i was getting this message due to a missing SPAN closing tag.

    here is the html which was causing this problem.

    this html is missing before

    after correcting it to below html i never got that message again.

  • Narsi

    Hi, i also faced this issue,i overcome this issue by dividing the continues dom execution , for this i used setTimeout function,resolving this issue is completely depends on how you are dividing the continuous execution

  • Hi Tim,

    I have a solution to this here:
    http://www.picnet.com.au/blogs/Guido/post/2010/03/04/How-to-prevent-Stop-running-this-script-message-in-browsers.aspx

    It basically just breaks up long/expensive tasks into manageable chunks. Works really well and stops those pesky ‘stop running this script’ dialogs.

    Thanks

    Guido

  • Thomasina Sluder

    Hi, I found this blog article while searching for help with JavaScript. I’ve recently switched browsers from Google Chrome to IE. After the change I seem to have a issue with loading JavaScript. Everytime I browse site that needs Javascript, the site does not load and I get a “runtime error javascript.JSException: Unknown name”. I cannot seem to find out how to fix the problem. Any help is very appreciated! Thanks