简体   繁体   中英

Lightbox: can't access parent javascript obj from iframe

I'm using a lightbox (highslide JS / highslide.com) which when opens displays a WYSIWYG Javascript editor (CKEditor / ckeditor.com). I call the lightbox (or expander) like so:

<a href="script.php" onclick="return hs.htmlExpand(this,{objectType:'iframe'})">click here</a>

In the parent page I include the javascript for the editor:

<script type="text/javascript" src="ckeditor/ckeditor.js"></script>

The first line (truncated) of ckeditor.js is:

(function(){if(window.CKEDITOR&&window.CKEDITOR.dom)return;if(!window.CKEDITOR)window.CKEDITOR=(function()

My problem, is that the editor does not work in the expander - TypeError: parent.window.hs.CKEDITOR is undefined

To fix this I need to call the ckeditor.js in script.php which makes the expander slow to open as it has to pull the JS file again, even though the parent window has already done so.

CK editor is called thus in iframe:

<script type="text/javascript">
CKEDITOR.replace( 'bodytext' ,
{
basePath : '/admin/ckeditor/'
});
</script>

I have tried prefixing CKEDITOR with 'parent' , 'parent.window', 'window' all without success

If there any fix for this?

Thank you!

I'm not sure I correctly understood your question, but based on:

In the parent page I include the javascript for the editor:

My answer is - you have to include ckeditor.js in the same document in which you use it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM