Situation: Invoking CKEDITOR in jQuery dialog box (many challenges here). My specific problem is that when I test for the existence of a CKEDITOR instance, I always get an error thrown.
BROWSERS tested: Firefox 21, IE 9, Safari 5.1.7
The error: Error: TypeError: CKEDITOR.instance is undefined
All of these ways of testing for the CKEDITOR instance always throw a javascript error:
if(! CKEDITOR.instance['editor']){
if(CKEDITOR.instance['editor']){
if(! typeof CKEDITOR.instance['editor'] == "undefined"){
if(! typeof(CKEDITOR.instance['editor']) == "undefined"){
if(typeof CKEDITOR.instance['editor'] != "undefined"){
if(typeof CKEDITOR.instance['editor'] !== "undefined"){
if(typeof CKEDITOR.instance['editor'] === "undefined"){
Of course I scoured StackOverflow before making this post. I have tried every combination of "typeof" and "undefined" that has been suggested on StackOverflow.
How can I test for the existence of the object instance if I get an error in the very testing for the existence of the instance? A conundrum!
You're testing the wrong object (or object property in this case). instance
is undefined, so you have to first check if instance
is defined before testing one of it's properties.
if ( CKEDITOR.instance && CKEDITOR.instance['editor'] ) {
or if you want to know when it is NOT defined,
if ( !CKEDITOR.instance || !CKEDITOR.instance['editor'] ) {