Hi,
I want to add a block of JavaScript code using a plugin that I have created. It works fine when I'm using Firefox, but in IE when I click "ok" and the code is inserted it clean my JS code.
How can I disable fck to don't clean it.
Thanks.
I want to add a block of JavaScript code using a plugin that I have created. It works fine when I'm using Firefox, but in IE when I click "ok" and the code is inserted it clean my JS code.
How can I disable fck to don't clean it.
Thanks.
RE: insert JS code
thank you.
Y.Chaouche
RE: insert JS code
Hi,
in my Ok() function I have:
function Ok()
{
/* ... some code do get vars ... */
var oDoc = oEditor.FCK.EditorDocument;
jsSpace = oDoc.createElement('TABLE');
jsSpace.border='0';
jsSpace.cellspacing='0';
jsSpace.cellpadding='0';
var tbody = jsSpace.appendChild(oDoc.createElement('TBODY'))
var tr = tbody.appendChild(oDoc.createElement('TR'));
var td = tr.appendChild(oDoc.createElement('TD'));
jsSpace.setAttribute('width', width);
jsSpace.setAttribute('height', height);
jsSpace.contentEditable = false ;
var jsCode = getJScode(var1, var2, var3);
td.innerHTML = jsCode;
oEditor.FCKUndo.SaveUndoStep() ;
oEditor.FCK.InsertElementAndGetIt(jsSpace);
return true;
}
My getJScode function returns some JS code with HTML like this:
function getJSCode(var1, var2, var3)
{
var str = '<div id="_id_"></div>';
str += '<scr'+'ipt type="text/javascript">';
str += 'document.write(\'<scr\'+\'ipt type="text/javascript" src="http://url_to_a_js_file.js"></scr\'+\'ipt>\');';
str += '</scr'+'ipt>';
str += '<scr'+'ipt type="text/javascript">';
str += 'function runJS(){';
str += '/* some JS code */';
str += '}';
str += 'document.onload=runJS;';
str += '</scr'+'ipt>';
}
When I use the plugin all of JS code is cleaned except the DIV tag.
Thank.
RE: insert JS code
Thanks again.
RE: insert JS code
1)You appendchild directly on the editordocument. I tried something similar and it works fine on ie and firefox. The code looks like this :
<code>
//create a place where to display information
var box = document.createElement('div');
box.setAttribute('style',"width:100%");
box.setAttribute('id','uppertextbox');
document.getElementsByTagName('body')[0].insertBefore(box,document.getElementsByTagName('table')[0]);
</code>
2)You have some curious code there :
str+="<scr" +"ipt type..."...
Why blow "script" into two parts ?
Y.Chaouche
RE: insert JS code
still not working :\
RE: insert JS code
Found de problem, but not the solution :\
Well, in IE I cant do td.innerHTML = '<script ></script>';
only can do
var js1 = td.appendChild(oDoc.createElement('SCRIPT'));
js1.setAttribute('type', 'text/javascript');
The problem now is:
I can set an attribute "src" to call an external JS file,
js1.setAttribute('src', 'http://url_to_a_js_file.js');
but if I want add some JS code in SCRIPT tag like:
js1.innerHTML = 'function hello(){alert(\'hello world\'); }';
or something like this.
I cant :\
Anyone knows how can I do this??
RE: insert JS code
... ...
var js1 = td.appendChild(oDoc.createElement('SCRIPT'));
js1.setAttribute('type', 'text/javascript');
js1.text = 'function hello(){alert(\'Hello World\')} document.onload=hello;';
...