Microsoft KB Archive/822534

= Internet Explorer Stops Responding When You Use a DHTML Edit Control to Delete the Last Cell or the Last Row of a Table =

Article ID: 822534

Article Last Modified on 10/13/2003

-

APPLIES TO


 * Microsoft Internet Explorer (Programming) 6 (SP1)

-



SYMPTOMS
Internet Explorer produces an access violation when you use the Dynamic HTML (DHTML) Editing Component to dynamically delete the last cell or the last row in a table.



RESOLUTION
To work around this issue, use DHTML to detect when you are about to delete the last row or the last cell. Do not call the ExecCommand (DECMD_DELETECELLS) method or the ExecCommand (DECMD_DELETEROWS) method. Instead, set the outerHTML to null:

 

   

// DECMD_INSERTTABLE=5022 // DECMD_DELETE=5004 // DECMD_DELETECELLS=5005 // DECMD_DELETECOLS=5006 // DECMD_DELETEROWS=5007

function OnInsertTable { document.mytableinfo.NumRows=1; document.mytableinfo.NumCols=2; document.mytableinfo.Caption = &quot;New Table &quot;; document.myedit.ExecCommand(5022,0,document.mytableinfo); }

function getSelectedTable { try {   ctlRg = document.myedit.DOM.selection.createRange; pelem=ctlRg.parentElement; i=0; while ((pelem.tagName!=&quot;TABLE&quot;)&&(i<20)) {       pelem=pelem.parentElement; i++; }   if (i==20) return -1; return pelem; } catch(e) {   return -1; } } function getNumCells { etable=getSelectedTable; if (etable!=-1) return etable.cells.length; else return -1; }

function ShowHTML { alert(document.myedit.DocumentHTML); }

function getNumRows { etable=getSelectedTable; if (etable!=-1) return etable.rows.length; else return -1; }

function OnDeleteRow { nbrows=getNumRows; if (nbrows==-1) return; if (nbrows==1) // if last row then delete it using DHTML {      getSelectedTable.outerHTML=''; } else document.myedit.ExecCommand(5007); }

function OnDeleteCell { nbcell=getNumCells; if (nbcell==-1) return; if (nbcell==1) // if last cell then delete it using DHTML {   getSelectedTable.outerHTML=''; } else document.myedit.ExecCommand(5005); }



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
  Paste the following code in Microsoft Notepad. Name the code Dhtmledit.htm :     <input type=&quot;button&quot; value=&quot;Delete Table Cell&quot; onclick=&quot;OnDeleteCell&quot;> <input type=&quot;button&quot; value=&quot;Show HTML&quot; onclick=&quot;ShowHTML&quot;>

// OLECMDEXECOPT_DODEFAULT=0 // DECMD_INSERTTABLE=5022 // DECMD_DELETE=5004 // DECMD_DELETECELLS=5005 // DECMD_DELETECOLS=5006 // DECMD_DELETEROWS=5007

function OnInsertTable { document.mytableinfo.NumRows=1; document.mytableinfo.NumCols=2; document.mytableinfo.Caption = &quot;New Table &quot;; document.myedit.ExecCommand(5022,0,document.mytableinfo); }

function OnDeleteRow { document.myedit.ExecCommand(5007); }

function OnDeleteCell { document.myedit.ExecCommand(5005); }

</li> <li>Double-click Dhtmledit.htm to open the page in Internet Explorer.</li> <li>Click Insert Table.</li> <li>Click inside the table, and then click Delete Row.</li> <li>Notice that Internet Explorer stops responding.</li></ol>

<div class="references_section">