Ir para conteúdo
Fórum Script Brasil
  • 0

Editor Rich Edit


Guest - Cesar -

Pergunta

Guest - Cesar -

Pessoal, preciso resolver a situação abaixo urgente. Estou pesquisando na net e não consigo encontrar nada.

Eu utilizo aqui em nosso e-mail interno na Intranet da empresa, um Editor Rich Edit (parecido o do hotmail). O problema é que ele funciona perfeitamente a uns 2 anos. Agora o pessoal aqui pretende instalar o SP2 do Window, mas ao instalar o SP2 quando ele tenta carregar a página quie contém o editor Rich Edit da erro de Permissão Negada no navegador (IE6).

Meu Deus me ajude o que faço... !!!

Se alguém quizer o código, ai vai.

-----------------------------------------------------------------------------------------------

var totenter = 0;

function initRichEdit(el) {

if (el.id) { // needs an id to be accessible in the frames collection

el.frameWindow = document.frames[el.id];

if (el.value == null)

el.value = el.innerHTML;

if ( el.value.replace(/\s/g, "") == "" )

el.value = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" +

"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" +

"<html>\n" +

"<head>\n<title></title>\n</head>\n<body>\n</body>\n</html>";

if (getIeVersion() >= 5.5)

el.src = "about:blank";

/*if (INFO.nmSRCLINK.value != "")

el.src = "http://intranet/documentacao/imgdoc/" + INFO.Setor.value + "/" + INFO.nmSRCLINK.value;

else

el.src = "about:blank";

*/

var d = el.frameWindow.document;

d.designMode = "On";

d.open();

d.write("<font size='2' face='Verdana, Arial, Helvetica, sans-serif'>" + INFO.txtMensagem.value + "</font>");

// d.write(INFO.txtMensagem.value);

d.close();

el.supportsXHTML = el.frameWindow.document.documentElement && el.frameWindow.document.childNodes != null;

// set up the expandomethods

// first some basic

el.setHTML = function (sHTML) {

el.value = sHTML;

initRichEdit(el);

}

el.getHTML = function () {

// notice that IE4 cannot get the document.documentElement so we'll use the body

return el.frameWindow.document.body.innerHTML;

// for IE5 the following is much better. If you don't want IE4 compatibilty modify this

//return el.frameWindow.document.documentElement.outerHTML;

}

el.getXHTML = function () {

if (!el.supportsXHTML) {

alert("Document root node cannot be accessed in IE4.x");

return;

}

else if (typeof window.StringBuilder != "function") {

alert("StringBuilder is not defined. Make sure to include stringbuilder.js");

return;

}

var sb = new StringBuilder;

// IE5 and IE55 has trouble with the document node

var cs = el.frameWindow.document.childNodes;

var l = cs.length;

for (var i = 0; i < l; i++)

_appendNodeXHTML(cs, sb);

return sb.toString();

};

el.setText = function (sText) {

el.value = sText.replace(/\&/g, "&amp;").replace(/\</g, "&lt;").replace(/\>/g, "&gt;").replace(/\n/g, "<br>");

initRichEdit(el);

}

el.getText = function () {

// notice that IE4 cannot get the document.documentElement so we'll use the body

// not hat it matters when it comes to innerText :-)

return el.frameWindow.document.body.innerText;

}

// and now some text manipulations

el.execCommand = function (execProp, execVal, bUI) {

return execCommand(this, execProp, execVal, bUI);

}

el.setBold = function () {

return this.execCommand("bold");

}

el.setItalic = function () {

return this.execCommand("italic");

}

el.setUnderline = function () {

return this.execCommand("underline");

}

el.setBackgroundColor = function(sColor) {

return this.execCommand("backcolor", sColor);

}

el.setColor = function(sColor) {

return this.execCommand("forecolor", sColor);

}

el.surroundSelection = function(sBefore, sAfter) {

var r = this.getRange();

if (r != null)

r.pasteHTML(sBefore + r.htmlText + sAfter);

};

el.getRange = function () {

var doc = this.frameWindow.document;

var r = doc.selection.createRange();

if (doc.body.contains(r.parentElement()))

return r;

// can happen in IE55+

return null;

};

/* modifies the enter keyup event to generate BRs. */

/* Enabled by default */

if (el.getAttribute("usebr")){

el.frameWindow.document.onkeydown = function () {

keyascii = el.frameWindow.event.keyCode

if (keyascii != 13) totenter = 0

if (keyascii == 13) { // ENTER

var sel = el.frameWindow.document.selection;

if (sel.type == "Control")

return;

totenter++;

if (totenter == 2){

insertTAG = "<P>";

}else{

insertTAG = "<BR>";

}

var r = sel.createRange();

r.pasteHTML(insertTAG);

el.frameWindow.event.cancelBubble = true;

el.frameWindow.event.returnValue = false;

r.select();

r.moveEnd("character", 1);

r.moveStart("character", 1);

r.collapse(false);

return false;

}

};

el.frameWindow.document.onkeypress =

el.frameWindow.document.onkeyup = function () {

if (el.frameWindow.event.keyCode == 13) { // ENTER

el.frameWindow.event.cancelBubble = true;

el.frameWindow.event.returnValue = false;

return false;

}

};

}

// Add your own or use the execCommand method.

// See msdn.microsoft.com for commands

// call oneditinit if defined

if (typeof el.oneditinit == "string")

el.oneditinit = new Function(el.oneditinit);

if (typeof el.oneditinit == "function")

el.oneditinit();

}

function execCommand(el, execProp, execVal, bUI) {

var doc = el.frameWindow.document;

var type = doc.selection.type;

var oTarget = type == "None" ? doc : doc.selection.createRange();

var r = oTarget.execCommand(execProp, bUI, execVal);

if (type == "Text")

oTarget.select();

return r;

}

}

function initAllRichEdits() {

var iframes = document.all.tags("IFRAME");

for (var i=0; i<iframes.length; i++) {

if (iframes.className == "richEdit")

initRichEdit(iframes);

}

}

function getIeVersion() {

var re = /MSIE (\d\.\d)/;

var a = re.exec(navigator.userAgent);

return a == null ? 0 : parseFloat(a[1]);

}

function doFormat(command) {

format = "HTML"

if (format!="HTML") {

displayError()

return

}

if (format=="HTML") {

if (arguments[1]=="CustomFont") {

arguments[1] = prompt("Com qual fonte você deseja formatar o texto?","Verdana, Arial, Helvetica, sans-serif")

}

if ((arguments[1]=="") && (arguments[0]=="forecolor")) {

arguments[1] = prompt("Qual a cor (ou código hexadecimal) que você deseja?\n(Em Inglês)","Black")

}

EDITOR.focus()

var edit = EDITOR.document.selection.createRange()

if (arguments[1]==null)

edit.execCommand(command)

else

edit.execCommand(command,false, arguments[1])

edit.select()

}

}

if (window.attachEvent) // IE5

window.attachEvent("onload", initAllRichEdits)

else if (document.all) // IE4

window.onload = initAllRichEdits;

Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

  • 0
Guest Visitante

esse erro de permissão negada é uma proteção do IE contra ataques de

XSS (Cross-Side Scripting)

esse erro impede que alguém "pesque" as informações do seu cartão de crédito

através de um iframe, por exemplo...

o IE só vai conseguir trabalhar com o conteúdo do iframe se

o URL dele pertencer ao mesmo domínio de seu 'parent'

quando você executa o código

-----------------------------------

if (getIeVersion() >= 5.5)

el.src = "about:blank";

-----------------------------------

você seta uma URL 'about:blank' para o document

isso faz com que o iframe não tenha o mesmo domínio do seu parent...

para corrigir esse erro, você pode, por exemplo,

montar uma página em branco e

fazer o carregamento dela, ao invés de

carregar about:blank

testa pra gente e manda o resultado depois..rsrs :-)

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.


  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...