简体   繁体   English

如何从iframe中调用主文档中的javascript函数(ckeditor插件)

[英]how to call javascript function in main document from within iframe (ckeditor plugin)

I've built a simple CKeditor 3 plugin with one button that should just call a JS-function when somebody clicks it. 我用一个按钮构建了一个简单的CKeditor 3插件,当有人单击它时应该只调用JS函数。

The plugin (code when somebody clicks) looks like this and is working: 插件(有人点击时的代码)如下所示,并且正在运行:

var openAssetsBrowser = {
    exec:function(editor){
        openAssetsBrowser();
    }
};

I always get the error "openAssetsBrowser is not a function" 我总是收到错误消息“ openAssetsBrowser不是函数”

The function itself is somewhere in the page, I thought the order shouldn't matter since the whole page is read first, before anyone would lclick the ckeditor button that triggers the function 该函数本身位于页面中的某处,我认为顺序无关紧要,因为先读取整个页面,然后再单击任何触发该函数的ckeditor按钮

Calling it on a link somewhere (eg with jquery) in the page just works: 在页面中某处的链接(例如,使用jquery)上调用它仅能起作用:

$("a#linkOpenFileManager").click(function(){
    openAssetsBrowser();        
        return(false);      
});

Does anyone know why the function cannot be called from within the CKeditor plugin? 有谁知道为什么不能从CKeditor插件中调用该函数?

update: when pasting the complete function code instead of "openAssetsBrowser();" 更新:粘贴完整的功能代码而不是“ openAssetsBrowser();”时 in the plugin, all works, but that's not really re-usable code... 在插件中,一切正常,但这并不是真正可重用的代码...

now that was easy. 现在很容易。

parent .openAssetsBrowser() did the trick! .openAssetsBrowser()做到了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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