"Web page editing" mode of text sending

Source: Internet
Author: User

1. Demand

Web page editing of third-party plug-ins a lot, I need to do a mobile phone on the release of pictures + text of the Lite Editor, text and pictures on the top-down arrangement is over.

IFrame has a lot of implementation architectures.

2. Realize

2.1 IFRAME Definition

2.2 Editing mode settings and focus fetching

Ifedit = This.getelementbyxid ("Ifedit"). Contentwindow;

Edit mode
IfEdit.document.designMode = "on";
IfEdit.document.contentEditable = true;

var GetPos = function () {
Debugger
Ifedit.pos = IfEdit.document.selection.createRange ();
};
IfEdit.document.body.onclick = GetPos;
IfEdit.document.body.onselect = GetPos;
IfEdit.document.body.onkeyup = GetPos;

2.3 Image Insertion function

function (HtmlElement) {
"<p><br>" + htmlelement + "</p>";
Ifedit.focus ();
var _image = document.createelement ("img");
_image.src=htmlelement;
_image.border= "0";
var iftemp = document.getElementById ("Ifedittemp");
Debugger

if (ifEdit.document.selection.type.toLowerCase ()! = "None")
{
IfEdit.document.selection.clear ();
}
IfEdit.pos.pasteHTML (_image.outerhtml);

Ifedit.focus ();
};

3. Questions

WeX5 schema, IFRAME does not selection this property. Dubugger found Event.target can get to the current node

3.1 Initializing an IFRAME

Ifedit = This.getelementbyxid ("Ifedit"). Contentwindow;
       
       //edit mode
         IfEdit.document.designMode = "on";
        ifEdit.document.contentEditable = true;
       
        var GetPos = function (event) {
            debugger;
            Ifedit.pos = event.target;// IfEdit.document.selection.createRange ();
       };
        IfEdit.document.body.onclick = GetPos;
        ifEdit.document.body.onselect = GetPos;
        ifEdit.document.body.onkeyup = GetPos;

3.2 Adding a child node on the body

Model.prototype.insertHtml = function (htmlelement) {
"<p><br>" + htmlelement + "</p>";
Ifedit.focus ();
var _image = document.createelement ("img");
_image.src=htmlelement;
_image.border= "0";
var iftemp = document.getElementById ("Ifedittemp");
Debugger

/*
if (ifEdit.document.selection.type.toLowerCase ()! = "None")
{
IfEdit.document.selection.clear ();
}*/

POS does not get focus, no last node, last node equals current node, append to Last
if (!ifedit.pos | |!ifedit.document.body.lastchild | |
IfEdit.document.body.lastChild = = Ifedit.pos) {
IfEdit.document.body.appendChild (_image);
}

else{
IfEdit.document.body.insertBefore (_image,ifedit.pos.nextsibling);
}

Ifedit.focus ();
};

"Web page editing" mode of text sending

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.