Select mshtml ActiveElement programatically

Is there a way to set the document ActiveElement in a mshtml WebBrowser programatically?
I'm trying to build an HTML editor with protected zones, and if the user clicks on an element I want to move them to an editable container.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can use focus() to do that. On any element in the DOM that can receive focus you can use focus():


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
garybarnesAuthor Commented:
That's what I thought. I can only therefore assume then that a DIV element is not focusable, because it's not working, although DIVs can be selected in the editor.Is there any way to make non-focusable elements the active element?
I was talking of a general HTML page inside a browser. It seems that you do something special. Normally, an element like a DIV cannot receive focus. Editor-style programs usually work around that by reacting to the onclick event (or mousedown) of a particular element, which is always there for visible elements, and then they show a different style (i.e., a fat border) to indicate that the element "has the focus".

In other words, editors program their own behavior for elements, which is different from the default behavior. Since the javascript + DOM event model is very rich, you can mimic many behaviors and turn any element into a focusable element. You can even add a focus() method to each element (but use the technique like in Prototype.js to do so).

On a side note, if it only needs to be working in IE (as it seems from your text) you may consider the contenteditable ="true" for an element to make it editable.
garybarnesAuthor Commented:
OK - I was able to simplify my page, and found that what I was trying to do will work (i.e. make a DIV receive focus) - but only if the DIV has an inline style statement containing a height or width component!
Thanks for your help - it pointed me in the right direction.
garybarnesAuthor Commented:
I wouldn't expect anyone to know this!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.