#1
  1. An Ominous Coward
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2002
    Posts
    4,425
    Rep Power
    0

    Angry Dr. Watson Killing JavaScript


    I have created a script that does this:

    1. User goes to a page with a form. Form has a text field, a drop down menu, and a group of radio buttons.
    2. User fills in / selects options using these form elements.
    3. User clicks submit and the script uses the options to determine some values to output.

    Values are output through a series of document.write() calls that create a new HTML page over the current one. The problem is this: we use a program that runs as TSR on our Windows NT Workstations that continually scans memory for leaks / violations / etc. Sometimes, this program kills IE5 when the script is executed within it saying that it caused an access violation.

    The problem appears to be the .write calls (determined by selectively commenting the code). However, I can't figure out why these simple .write calls are causing access violations. I have another script that works perfectly using .write calls to build a new page from within IE5. The problem seems to be appearing randomly. Sometimes it happens frequently, sometimes it happens rarely. Unfortuneatly, disabling the scanning TSR on all 450 PCs that use this is NOT an option

    Any input?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    try not to document.write() to the "main" document, but use
    Code:
    document.all['xyz'].document.write
    OR
    document.all['xyz'].innerHTML=...
    and an empty anchor in the body:
    <a name="xyz"></a>

    this helped me in a problem where document.write sometimes worked, sometimes not.
  4. #3
  5. An Ominous Coward
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2002
    Posts
    4,425
    Rep Power
    0
    Thanks for responding. I'm buried under some other projects now, but as soon as I have a chance to try it I will post back whether it worked or not!
  6. #4
  7. An Ominous Coward
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2002
    Posts
    4,425
    Rep Power
    0
    Gaaa! Stupid IE. Thanks M.Hirsch, but that causes it to err out. Here's the code that the memory faults actually occur in:

    PHP Code:
    else {            // if which_page is NOT "Web"

    a=0;

    while(
    listID.length)    // step through the listID[]s and .write one piece of HTML for each one.
        
    {
    document.write("<table border=\"0\" width=\"460\" cellspacing=\"0\" cellpadding=\"0\">");
    document.write("<tr><td><font face=\"Verdana\" size=\"1\"><b>Month and Year of Campaign \/ List ID #<\/b>&nbsp&nbsp&nbsp<a href=");
    document.write("http://bomcpa23/Bsphelp/Enrollments/West/Counts_As_2/");
    document.write(campaign[a]);
    document.write(".htm#");
    document.write(listID[a]);
    document.write(" onmouseover=\"this.style.color = \'green\'\;\" onmouseout=\"this.style.color = \'#0000FF\'\;\">");
    document.write(campaign[a]+" / #");
    document.write(listID[a])
    document.write("</a></FONT><BR><BR></td></tr></table>");
    a++;
        }

    Something wrong with it? Seems sorta iffy, but it should work, and usually does, but randomly it acts like it causes a memory fault and the browser crashes. Usually this loop goes 3 or 4 times, never more than 5.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    2
    Rep Power
    0
    I'm having the same problem. Did either of you ever resolve yours satisfactorily? I won't attempt to relate my source code and everything I've tried, because it's too flaky and I don't want to overwhelm you. Just suffice it to say I haven't figured it out yet and would like to hear more about either of your experiences.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    uh, odd that i didnīt answer this post. the notification email must have been eaten by my anti-spam soft (i deinstalled it, it refused to accept more than 10 messages from devshed per day) or my post must have got lost somehow in the big crash...

    i think you have to put "document.open()" and "document.close()" around the "document.write()" commands.

    also, did you try the "empty anchor" approach? it works fine for me...
    if this does not help, you need to post the actual code.

    note: recently i had IE6 crash when a php script failed and thus non-valid html was output to the client (missing close-tags). seems to be a bug (no SP1 installed yet...)
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    2
    Rep Power
    0
    Thanks for the prompt response. While I didn't actually try your anchor tag suggestion, I did try the alternative, setting the .innerHTML property of a DIV tag on the target page, and that did seem to help. But this is in context of a generic module, and as I tried to add more and more of the functionality back in, which I had taken out for the baseline, it started happening again.

    I also just tried the document.open() and document.close() statements, but they didn't seem help either. Good "best practices" lesson for me, though.

    I don't want to spend any more time on this right now, I've got too much else to do, but I thank you for your suggestions. The need for this right now is not great enough to warrant spending any more time on it. It could be that it is actually related to the application around it in some unseen way (which would explain why it worked fine until recently), and I don't think we want to get into debugging my entire application here...
  14. #8
  15. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    Just a note for anyone who is following this:

    You should never call document.write() from an event handler. The fact that it sometimes works in Internet Explorer is irrelevant - document.write() automatically clears the current document which includes the script that's calling it! If it works, it's freakish and anything but robust, and there are numerous other solutions. This is not PHP, and you're not echoing to a document-in-progress, you're dealing with a fully-loaded page, and DHTML/DOM approaches are called for.
  16. #9
  17. An Ominous Coward
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2002
    Posts
    4,425
    Rep Power
    0
    This thread is so ludicrously old that all of the information this code originally manipulated is long archived and the code defunct. It's like a bloody time capsule

    But, ultimately, I did learn the lesson that adios pointed out. Try writing to an iframe or some similar solution and see if that works instead.

IMN logo majestic logo threadwatch logo seochat tools logo