【问题标题】:CKEditor iOS Get HTML Editor Contents on Button EventCKEditor iOS 在按钮事件上获取 HTML 编辑器内容
【发布时间】:2017-01-04 05:20:35
【问题描述】:

我正在使用 CKEditor。用户更改编辑器中的文本后,我需要以某种方式“保存”用户更改。

我已经尝试过搜索,但没有找到我需要的东西。

请大家帮忙,尝试在我的应用中安装 CKEditor 对我来说是一段漫长而艰难的旅程。

【问题讨论】:

    标签: javascript ios objective-c webview ckeditor


    【解决方案1】:

    我找到了问题的解决方案。

    用户修改WKWebView中的CKEditor editor1标签中的信息后,需要在webView上运行如下方法。

    我必须添加“textToHTML”方法,因为检索到的 HTML 并将其放置到字符串中将诸如“

        - (IBAction)saveButtonItemPressed:(UIBarButtonItem *)sender {
    
        // Save HTML contents of Editor Window
        [self getEditorHTMLContents:^(NSString *result) {
            NSString *editorContents1 = [self textToHtml:result];
            NSLog(@"%@",editorContents1);
        }];
    
    }
    
    -(void)getEditorHTMLContents:(void(^)(NSString* result))onFinish {
    
        __block NSString *content;
    
        // Script to get content of Editor1
        NSString *script = @"(CKEDITOR.instances['editor1'].getData());";
    
        [self.webView evaluateJavaScript:script completionHandler:^(id _Nullable result, NSError * _Nullable error) {
    
            content = (NSString *)result;
    
            if (error) {
                NSLog(@"%@",error);
            }
    
            if (onFinish) onFinish(content);
        }];
    
    }
    
    - (NSString*)textToHtml:(NSString*)htmlString {
    
        if (!htmlString) return @"ERROR";
    
        htmlString = [htmlString stringByReplacingOccurrencesOfString:@"&" withString:@"&" ];
        htmlString = [htmlString stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<" ];
        htmlString = [htmlString stringByReplacingOccurrencesOfString:@"&gt;" withString:@">" ];
        htmlString = [htmlString stringByReplacingOccurrencesOfString:@"&quot;" withString:@""""];
        htmlString = [htmlString stringByReplacingOccurrencesOfString:@"&#039;" withString:@"'" ];
    
        htmlString = [htmlString stringByReplacingOccurrencesOfString:@"</p><p>" withString:@"\n"];
        //  htmlString = [htmlString stringByReplacingOccurrencesOfString:@"\n" withString:@"<br />"];
        while ([htmlString rangeOfString:@"&nbsp;&nbsp;"].length > 0) {
            htmlString = [htmlString stringByReplacingOccurrencesOfString:@"&nbsp;&nbsp;" withString:@"  "];
        }
        return htmlString;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多