Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMNSHTMLDocument.execCommand]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://localhost/NAVARCLES/index.php...s&verif=afegir :: tbclick :: line 378" data: no]
Para que se vea más claro os pongo el còdigo aquí marcando las partes para que lo entendais un poco:
Código:
function InitToolbarButtons() { kids = document.getElementsByTagName('DIV'); //Creación del objeto donde hay los mètodos de los eventos ev=new eventos(this.ident); for (var i=0; i < kids.length; i++) { if (kids[i].className == 'imagebutton') { //Aquí se substituyen las acciones de los eventos que ya estan definidos por los qie hay dentro del objeto acabado de crear kids[i].onmouseover = ev.MOver; kids[i].onmouseout = ev.MOut; kids[i].onmousedown = ev.MDown; kids[i].onmouseup = ev.MUp; kids[i].onclick = ev.MClick; } } } function tbmousedown(e) { this.firstChild.style.left = 2; this.firstChild.style.top = 2; this.style.border='inset 1px'; e.preventDefault(); } function tbmouseup() { this.firstChild.style.left = 1; this.firstChild.style.top = 1; this.style.border='outset 1px'; } function tbmouseout() { this.style.border='solid 1px #80B7EB'; } function tbmouseover() { this.style.border='outset 1px'; } function insertNodeAtSelection(win, insertNode) { // get current selection var sel = win.getSelection(); // get the first range of the selection // (there's almost always only one range) var range = sel.getRangeAt(0); // deselect everything sel.removeAllRanges(); // remove content of current selection from document range.deleteContents(); // get location of current selection var container = range.startContainer; var pos = range.startOffset; // make a new range for the new selection range=document.createRange(); if (container.nodeType==3 && insertNode.nodeType==3) { // if we insert text in a textnode, do optimized insertion container.insertData(pos, insertNode.nodeValue); // put cursor after inserted text range.setEnd(container, pos+insertNode.length); range.setStart(container, pos+insertNode.length); } else { var afterNode; if (container.nodeType==3) { // when inserting into a textnode // we create 2 new textnodes // and put the insertNode in between var textNode = container; container = textNode.parentNode; var text = textNode.nodeValue; // text before the split var textBefore = text.substr(0,pos); // text after the split var textAfter = text.substr(pos); var beforeNode = document.createTextNode(textBefore); var afterNode = document.createTextNode(textAfter); // insert the 3 new nodes before the old one container.insertBefore(afterNode, textNode); container.insertBefore(insertNode, afterNode); container.insertBefore(beforeNode, insertNode); // remove the old node container.removeChild(textNode); } else { // else simply insert the node afterNode = container.childNodes[pos]; container.insertBefore(insertNode, afterNode); } range.setEnd(afterNode, 0); range.setStart(afterNode, 0); } sel.addRange(range); }; function getOffsetTop(elm) { var mOffsetTop = elm.offsetTop; var mOffsetParent = elm.offsetParent; while(mOffsetParent){ mOffsetTop += mOffsetParent.offsetTop; mOffsetParent = mOffsetParent.offsetParent; } return mOffsetTop; } function getOffsetLeft(elm) { var mOffsetLeft = elm.offsetLeft; var mOffsetParent = elm.offsetParent; while(mOffsetParent){ mOffsetLeft += mOffsetParent.offsetLeft; mOffsetParent = mOffsetParent.offsetParent; } return mOffsetLeft; } //En esta funcion (vinculada al método MClick) es donde al ejecutarse cualquier execCommand me da el error anteriormente citado function tbclick() { if ((this.id == 'forecolor') || (this.id == 'hilitecolor')) { parent.command = this.id; buttonElement = document.getElementById(this.id); document.getElementById('colorpalette').style.left = this.GOffsetLeft(buttonElement); document.getElementById('colorpalette').style.top = this.GOffsetTop(buttonElement) + buttonElement.offsetHeight; document.getElementById('colorpalette').style.visibility='visible'; } else if (this.id == 'createlink') { var szURL = prompt('Enter a URL:', 'http://'); if ((szURL != null) && (szURL != '')) { document.getElementById(ev.identify).contentWindow.document.execCommand('CreateLink',false,szURL); } } else if (this.id == 'createimage') { imagePath = prompt('Enter Image URL:', 'http://'); if ((imagePath != null) && (imagePath != '')) { document.getElementById(ev.identify).contentWindow.document.execCommand('InsertImage', false, imagePath); } } else if (this.id == 'createtable') { e = document.getElementById(ev.identify); rowstext = prompt('enter rows'); colstext = prompt('enter cols'); rows = parseInt(rowstext); cols = parseInt(colstext); if ((rows > 0) && (cols > 0)) { table = e.contentWindow.document.createElement('table'); table.setAttribute('border', '1'); table.setAttribute('cellpadding', '2'); table.setAttribute('cellspacing', '2'); tbody = e.contentWindow.document.createElement('tbody'); for (var i=0; i < rows; i++) { tr =e.contentWindow.document.createElement('tr'); for (var j=0; j < cols; j++) { td =e.contentWindow.document.createElement('td'); br =e.contentWindow.document.createElement('br'); td.appendChild(br); tr.appendChild(td); } tbody.appendChild(tr); } table.appendChild(tbody); insertNodeAtSelection(e.contentWindow, table); } } else { parent.document.getElementById(ev.identify).contentWindow.document.execCommand(this.id, false, null); } } function Select(selectname) { var cursel = document.getElementById(selectname).selectedIndex; /* First one is always a label */ if (cursel != 0) { var selected = document.getElementById(selectname).options[cursel].value; document.getElementById(this.ident).contentWindow.document.execCommand(selectname, false, selected); document.getElementById(selectname).selectedIndex = 0; } document.getElementById(this.ident).contentWindow.focus(); } function dismisscolorpalette() { document.getElementById('colorpalette').style.visibility='hidden'; } function getHtml(form,formnot) { if(ie){ var editor_obj = document.all[this.ident]; }else if (n6){ var editor_obj = document.getElementById(this.ident); } formnot.value=editor_obj.contentWindow.document.body.innerHTML; form.submit(); } //Constructor del objeto padre que contiene en el mètodo IToolbarButtons (funcion InitToolbarButtons) la creación del objeto que contiene los metosos de eventos function Editor(id) { this.ident=id; alert(this.ident); document.getElementById(this.ident).contentWindow.document.designMode = 'on'; //try { // document.getElementById('edit').contentWindow.document.execCommand('undo', false, null); //} catch (e) { // alert('This demo is not supported on your level of Mozilla.'); //} this.IToolbarButtons=InitToolbarButtons; this.INodeAtSelection=insertNodeAtSelection; this.GOffsetTop=getOffsetTop; this.GOffsetLeft=getOffsetLeft; this.ISelect=Select; this.Dcolorpalette=dismisscolorpalette; this.GHtml=getHtml; this.IToolbarButtons(); document.addEventListener('mousedown', this.Dcolorpalette, true); document.getElementById(this.ident).contentWindow.document.addEventListener('mousedown', this.Dcolorpalette, true); document.addEventListener('keypress', this.Dcolorpalette, true); document.getElementById(this.ident).contentWindow.document.addEventListener('keypress', this.Dcolorpalette, true); } //Constructor del objeto que contiene los mètodos de eventos function eventos(id) { this.identify=id; this.MDown=tbmousedown this.MUp=tbmouseup; this.MOut=tbmouseout; this.MOver=tbmouseover; this.MClick=tbclick; }
Seguiré buscando el problema, pero si alguien lo ve le agradeceria mucho que lo posteara.
Muchas gràcias
PD: El còdigo es de un editor wysiwig que esta en la web de mozilla.