none
SetAttribute cause a dammy Undo item on Webbrowser control with IE11 issue

    Question

  • Hi All,

    My application is using DesignMode feature on Webbrowser control. I'm getting my application to support IE11.

    We normally preper some date when the page is loaded accroding different users, and use SetAttribute to set the value. That works fine on IE10 and before.

    Starts from IE11, I find the SetAttribute will create a Undo action which User can reverte my hard code action by using undo/redo feature.

    To reproduce this issue, we call create a general winform application and drop a webbrowser control on it,

     private void Form1_Load(object sender, EventArgs e)
            {
                webBrowser1.DocumentText = "<html><body><input/></body></html>";
                webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
                
            }
    
    
    
            private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                IHTMLDocument2 doc = webBrowser1.Document.DomDocument as IHTMLDocument2;
    
                var undoresult = doc.queryCommandEnabled("Undo");
    
                foreach (IHTMLElement ele in doc.body.children)
                {
                    ele.setAttribute("value", "<@>", 0);
                }
    
                var undoresult2 = doc.queryCommandEnabled("Undo");
    
                MessageBox.Show(String.Format("before setvalue Undo is {0}, after is {1}",undoresult,undoresult2));
            }

    When we run the code with IE9/10, both Undo states are false. However, in IE11, after call setAttribute, the Undo becomes true, and we can call execute undo to revert the set action, which is unexpected.

    Is this a bug on IE11? Any workaround to make Undo works as before?

    Regards,

    Yi

     

    MSC on Computer Science (Parallel algorithm)

    Thursday, December 26, 2013 8:38 AM

Answers

  • Hi Yi Feng,

    I am working with Barry to help you on this case.

    I just reviewed all your input above, and found now you have the following questions:

    Q: "The rest question is to MSFT, is this a bug in IE11? "

    A: No, it isn't. It is a new feature mentioned in http://blogs.msdn.com/b/ie/archive/2013/10/24/enhanced-rich-editing-experiences-in-ie11.aspx

    Q: "Do you guys believe any other things I need to care?"

    A: Since I do not have your project on hand, I cannot directly point it out. But I think there were some other changes on DOM were put into the undostack. Instead of marking as readonly, we can also try to clear the undostack by calling ClearUndoStack IE command. http://msdn.microsoft.com/en-us/library/hh801227(v=vs.85).aspx#ClearUndoStack 

    webBrowser1.Document.ExecCommand("ms-clearUndoStack");

    Let me know if we can get it work in your project.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, December 31, 2013 1:21 AM

All replies

  • Hi, YiFeng

    Maybe you can use this workaround: 

    foreach (IHTMLElement ele in doc.body.children) {

    ele.setAttribute("readonly", "readonly", 0); ele.setAttribute("value", "<@>", 0);}

    Regards,

    Thursday, December 26, 2013 12:42 PM
  • Great!!

    This workaround works. I adjust a little bit to make it editable.

     ele.setAttribute("readonly", "readonly", 0);
                    ele.setAttribute("value", "<@>", 0);
                    ele.removeAttribute("readonly", 0);

    Thank you very much.

    The rest question is to MSFT, is this a bug in IE11?


    MSC on Computer Science (Parallel algorithm)

    Friday, December 27, 2013 2:26 AM
  • I double check the above workaround on my sample winform application, it works.

    However, when I adapt it into my project, it doesn't work. No matter "readOnly" is set, when I set value for a input, it will make "undo" enable.

    Do you guys believe any other things I need to care?

    Regards,

    Yi


    MSC on Computer Science (Parallel algorithm)

    Friday, December 27, 2013 8:56 AM
  • Hi YiFeng,

    I'm trying to consult this issue, please wait for my response.

    Regards,



    Barry Wang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, December 27, 2013 9:42 AM
  • Hi Yi Feng,

    I am working with Barry to help you on this case.

    I just reviewed all your input above, and found now you have the following questions:

    Q: "The rest question is to MSFT, is this a bug in IE11? "

    A: No, it isn't. It is a new feature mentioned in http://blogs.msdn.com/b/ie/archive/2013/10/24/enhanced-rich-editing-experiences-in-ie11.aspx

    Q: "Do you guys believe any other things I need to care?"

    A: Since I do not have your project on hand, I cannot directly point it out. But I think there were some other changes on DOM were put into the undostack. Instead of marking as readonly, we can also try to clear the undostack by calling ClearUndoStack IE command. http://msdn.microsoft.com/en-us/library/hh801227(v=vs.85).aspx#ClearUndoStack 

    webBrowser1.Document.ExecCommand("ms-clearUndoStack");

    Let me know if we can get it work in your project.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, December 31, 2013 1:21 AM
  • Thanks Alan,

    I will get back to you once I try your suggestion on my project.

    Regards,

    Yi


    MSC on Computer Science (Parallel algorithm)

    Tuesday, December 31, 2013 4:27 AM
  • it works.

    Thank you.


    MSC on Computer Science (Parallel algorithm)

    Tuesday, December 31, 2013 4:39 AM