ASP.NET HTML Editor - Knowledge Base

« Back to Knowledge Base list

Click to <DIV> element once

Q:

I use the Editor control to edit some documents. These documents contain <DIV> elements with some text which I want to edit. In FireFox I click to the <DIV> element once and can edit its content, but in IE I should click TWICE to edit the content inside the <DIV> element.

What should I do to be able to edit the content immediately without having to double-click on it?

A:

Just place the following script block into your page:

<script type="text/javascript">
    // when Editor loaded
    function EditorOnLoad(editor) {
        // for IE only
        if (HTMLEditor.is_ie) {
            if (!editor.__savedActivate) {
                // save original "Design mode" activate method
                editor.__savedActivate = editor.activate;
                // redefine "Design mode" activate method
                editor.activate = function(par) {
                    var editor = this;
                    this.isActivated = false;
                    // call the original method
                    this.__savedActivate(par);
                    this.__checkActivation();
                };
                // be sure that "Design mode" is activated
                editor.__checkActivation = function() {
                    if (this.isActivated) {
                        prepareDesignMode(this); // when activated
                    } else {
                        var editor = this; // wait a bit
                        setTimeout(function() { editor.__checkActivation(); }, 200);
                    }
                };
            }
            prepareDesignMode(editor);
        }
    }
    // change "Design mode" document body's behaviour
    function prepareDesignMode(editor) {
        // when any control selected
        HTMLEditor._addEvent(editor.getDocument().body, "controlselect", handle_control_select);
    }
    function handle_control_select(e) {
        // if DIV only
        if (e.srcElement.tagName && e.srcElement.tagName.toLowerCase() == "div") {
            // go to within the div
            setTimeout("moveToText(" + e.clientX + ", " + e.clientY + ")", 1);
            return false;
        }
        return true;
    }
    function moveToText(x, y) {
        // get the Editor's client-side object
        var inst = oboutGetEditorByClientId("<%= editor1.ClientID %>");
        // create text range in the edit panel
        var rng = inst.getDocument().body.createTextRange();
        // move the range to the point
        rng.moveToPoint(x, y);
        // collapse range to cursor
        rng.collapse();
        // 'highlight' the cursor
        rng.select();
    }
</script>
obout.com
obout.com Home
News
HTML Editor Home
HTML Editor Home
Why the best?
Download
Site Map
Examples - 80
Appearance - 10
Full button set
Lite button set
Custom button set
Design-mode textbox
How to fit into small space
Page maker
Default font
Initially without toolbar
Preview mode
"Read only" mode New
Content - 16
Read-only and custom tags
Shadow for Image
External image gallery
Upload images
Copy/paste formatting
Preview Document appearance
Keys used for editing
.NET validation
Documents Generator
Upload documents
Convert to PDF
FullHTML
Editor and database
Spell Checker - 3
Spell checking
Spell Checker dictionaries
Several dictionaries
Localization - 2
Localization
RTL support
Integration - 9
Inside Flyout
Inside Grid
Inside Window
With Color PickerNew
Google AJAX Language API New
Inside AJAX Page
Inside CallbackPanel
MultiView
Wizard
ASP.NET AJAX ControlToolkit - 5
Collapsible panel
Tabs
Editor in each TabPanel New
Timer
Modal popup
Server-Side API - 13
Content counters
Plain text length control
Show plain text
Enable editor on focus
Set caret position on load
Add CSS files New
Hide HTML Editor until needed
FixedToolBar
CSS file for quick format
Set HTML view on load
Enable browse button for images
Enable browse button for URLs
Disable Wait message New
Server-Side Events - 5
ClickSubmit event
ClickCancel event
ContentChanged event
CallbackContent
ClientCancel
Client-Side API - 10
Working with selected text
Set design/HTML view on load
Show/hide HTML Editor
Get/set content
Surround HTML
Insert HTML
Style selected content
Exec command
Query command
'Not Set' in dropdowns New
Customize - 17
Custom editor toolbar in VS
Custom fonts
Custom font sizes
How to add icons
Custom Popup Windows
Custom Buttons
Custom Context Menu
Popup Properties Disabling
Default Table Properties
Custom toggle button
Custom select button
Textarea popup
Custom 'Quote' button New
Show/hide submit button
Show/hide Design/HTML view
Show/hide quick format panel
Width & Height
Knowledge Base - 1
Knowledge Base
Documentation - 23
Server side
HTML Editor properties & events
HTML Editor inner properties
Custom toolbar
Custom fonts
Custom font sizes
Custom Context Menu
Dictionaries for spell checker
Hot keys definition
Disabling Context Menu items
Additional CSS files New
Client side
Main functions and interfaces
Custom Context Menu support
Custom Popup Window support
Top toolbar buttons' methods
State functions
Suppress Context Menu
Spelling dictionary
Dictionary structure
Affix rules
Phonetic rules
Generate phonetic code
How to add new word
Supported browsers
ChangeLog
Tutorials - 6
Using the correct path
Autosave implementation
Full custom buttons set
Editor_data for several sites
Use with database
Template XML file use New