Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#10379 closed Bug (invalid)

"unescape" undefined.

Reported by: Siamot Owned by:
Priority: Normal Milestone:
Component: General Version: 3.6.2
Keywords: Cc:

Description

I'm using ckeditor in my ASP.Net MVC 3 project, which structs with jQuery 1.7.2 and jquery.easyui. In this project, I created a View with ckeditor textarea in it, while the page reloading, the explorer shows an error: "unescape" undefined. Here is my way to init ckeditor:

var g_Editor;
function initCKEditor() {
    g_Editor = CKEDITOR.instances['txtContent'];
    if (g_Editor) {
        CKEDITOR.remove(g_Editor);
    };
    g_Editor = CKEDITOR.replace("txtContent");
    g_Editor.setData($("#Content").val());
}

And I use "g_Editor" to get data from the ckeditor textarea. If the code is removed, the error "'unescape' undefined" is gone too... Is there something wrong with my code? Or this is a bug?

Attachments (2)

ckeditor error 堆栈调用.jpg (20.1 KB) - added by Siamot 11 years ago.
ckeditor error 2.jpg (408.1 KB) - added by Siamot 11 years ago.
An error occurred while ckeditor processing function destroy(). This is the place where error occurred in ckeditor source code.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 11 years ago by Siamot

Sorry, I miswrote the title, it should be: "unescape" undefined.

comment:2 Changed 11 years ago by Siamot

Summary: "escape" undefined."unescape" undefined.

comment:3 Changed 11 years ago by Jakub Ś

Keywords: 'unescape' undefined removed
Resolution: invalid
Status: newclosed

I see two.

  1. You can't use remove method http://docs.ckeditor.com/#!/api/CKEDITOR-method-remove you should use destroy instead
  2. You hurry too much. Editor isn't just some styled div but large application and despite how fast your browser is it needs some time to clean up. You should fire your commands when certain event occurs.

Try creating something like code below:

var g_Editor;
	function a(){
		g_Editor = CKEDITOR.instances['editor1'];
		if (g_Editor) {        
			g_Editor.destroy();
			g_Editor = null;			
		}
		b();
	}
	
	function b(){
		//if(!g_Editor)
			//return;
		g_Editor = CKEDITOR.replace('editor1');
		g_Editor.on('instanceReady', function(){
			g_Editor.setData('<p>test</p>');
		})
	}	

comment:4 Changed 11 years ago by Jakub Ś

Please note that when you have e.g. CKEditor 3.6.4 ASP.NET you can use ckeditor 4 client-side version with it.

Just open downloaded CKEditor_ASPNET/_Samples, remove ckeditor folder and paste ckeditor folder for version for you have downloaded from http://ckeditor.com/download (Please use full package)

comment:5 in reply to:  3 Changed 11 years ago by Siamot

Replying to j.swiderski:

I see two.

  1. You can't use remove method http://docs.ckeditor.com/#!/api/CKEDITOR-method-remove you should use destroy instead
  2. You hurry too much. Editor isn't just some styled div but large application and despite how fast your browser is it needs some time to clean up. You should fire your commands when certain event occurs.

Try creating something like code below:

var g_Editor;
	function a(){
		g_Editor = CKEDITOR.instances['editor1'];
		if (g_Editor) {        
			g_Editor.destroy();
			g_Editor = null;			
		}
		b();
	}
	
	function b(){
		//if(!g_Editor)
			//return;
		g_Editor = CKEDITOR.replace('editor1');
		g_Editor.on('instanceReady', function(){
			g_Editor.setData('<p>test</p>');
		})
	}	

Thanks! I tried your method by using destroy(), but there is another error occured while reloading:

While ckeditor processing function destroy(), the ide caught an exception:

Microsoft JScript runtime error: Can not get the value of property "document": the object is null or undefined.

PS: In this project, we're using ckeditor with jQuery, not the way with ASP.NET. PS 2: Sorry for my bad English. - -!

Changed 11 years ago by Siamot

Changed 11 years ago by Siamot

Attachment: ckeditor error 2.jpg added

An error occurred while ckeditor processing function destroy(). This is the place where error occurred in ckeditor source code.

comment:6 Changed 11 years ago by Siamot

I tracked the process, and then found that the error occurred while running the code below:

"getFrameDocument:function(){var i=this.$;try{i.contentWindow.document;}", i.contentWindow.document, the value of property "contentWindow" is null, so ...

comment:7 Changed 11 years ago by Jakub Ś

  1. With MS frameworks it is recommended to use CKEditor ASP.NET and not only plain CKEditor JavaScript as you may get into some weird problems.
  2. How do you reload your page - is this traditional submit or some partial reloads, periodic refreshes etc.?
  3. Is there any chance for providing reduced (as small as possible) sample application showing this problem in code? Perhaps there is a simple fix for it.
  4. You could try setting timeout on b(); perhaps it will work.
  5. "And I use "g_Editor" to get data from the ckeditor textarea." If you do some partial page reloads then perhaps what you can do is destroy editor before this takes place and load it back again when part of page is loaded.

comment:8 in reply to:  7 Changed 11 years ago by Siamot

Replying to j.swiderski:

  1. With MS frameworks it is recommended to use CKEditor ASP.NET and not only plain CKEditor JavaScript as you may get into some weird problems.
  2. How do you reload your page - is this traditional submit or some partial reloads, periodic refreshes etc.?
  3. Is there any chance for providing reduced (as small as possible) sample application showing this problem in code? Perhaps there is a simple fix for it.
  1. You could try setting timeout on b(); perhaps it will work.
  2. "And I use "g_Editor" to get data from the ckeditor textarea." If you do some partial page reloads then perhaps what you can do is destroy editor before this takes place and load it back again when part of page is loaded.

Thanks for your patience and particular help! Yesterday I found "You hurry too much" in your comment, then I realized that maybe not all of the ckeditor elements were loaded.So I tried the "timeout" way and it worked! That's why I was so excited when I saw the third point of your comment this morning! Here is my code:

var g_Editor;
var initIntervalID;
function initCKEditor() {
    initIntervalID = setInterval(createCKEditor, 1);
}
function createCKEditor() {
    g_Editor = CKEDITOR.instances['txtContent'];
    if (!g_Editor) {
        g_Editor = CKEDITOR.replace("txtContent");
        g_Editor.on('instanceReady', function () {
            g_Editor.setData($("#Content").val());
        })
        clearInterval(initIntervalID);
    }
    else {
        CKEDITOR.remove(g_Editor);
        g_Editor = null;
    }
}

You may notice that I didn't use "destroy()" but "remove()" to release the existing instance, that's because when I tried to use "destroy()", the exception in comment:5 happend again. But I tried to use "remove()" and the exception was gone. I guess that maybe some scripts I referenced in my project overwrote or encapsulated some functions of jQuery, and perhaps there's some collisions with the function "destroy()" in ckeditor. But now our team is on a fast marching that we do not have enough time to find out what the collision is, I'm sorry for that.

Thank you again for your help'''

comment:9 Changed 11 years ago by Jakub Ś

The problem is that remove function just deletes editor instance name from global CKEDITOR object while destroy removes all listeners and deletes editor instance name from global CKEDITOR object. Using only remove can cause memory leaks.

I would rather keep experimenting. Perhaps with something like:

var g_Editor;
		function createCKEditor() {
			g_Editor = CKEDITOR.instances['editor1'];
			if (!g_Editor) {					
					g_Editor = CKEDITOR.replace("editor1");
						g_Editor.on('instanceReady', function () {
							g_Editor.setData('test');
					});     
			}
			else {				
				g_Editor.destroy(true);
			}
		}
		
		CKEDITOR.on( 'instanceDestroyed', function(){
			if(g_Editor) g_Editor = null;
			g_Editor = CKEDITOR.replace("editor1");
			g_Editor.on('instanceReady', function () {
				g_Editor.setData('test');
			});
		});
Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy