CLEditerの実装をした際にリンク機能に元々なかった、別タブで開くかどうかを選べるチェックボックを追加いたしました。
そこで一つ問題が発生しました。
テキストエリア内の好きなところで1クリックか改行を行わないと反映が無効になってしまうという事象が起こります。
別タブでのリンク設定後に何もせずに更新、またはソースの参照を行うと<a>で囲ってあったはずのテキストが元のテキストに戻ってしまいます。
下記が追加の記載をしたコードになります。
if (url !== ""){ if ($("#blank").is(':checked')) { editor.doc.execCommand("insertHTML", false, '<a href="' + url + '" target="_blank" rel="noopener noreferrer">' + selectedText(editor) + '</a>'); } else { execCommand(editor, data.command, url, null, data.button); } // Reset the text, hide the popup and set focus $text.val("https://"); hidePopups(); focus(editor); }
また、下記のコードを追加して試して見たのですが、解決しませんでした。
// copy all the editor's iframe HTML and send it to textarea (queer solution but that's all I was able to come up with) var iframe_content = $('#area_cont').contents().find("body").html(); $('#input').html(iframe_content); 【追加後】 if (url !== ""){ if ($("#blank").is(':checked')) { editor.doc.execCommand("insertHTML", false, '<a href="' + url + '" target="_blank" rel="noopener noreferrer">' + selectedText(editor) + '</a>'); // copy all the editor's iframe HTML and send it to textarea (queer solution but that's all I was able to come up with) var iframe_content = $('#area_cont').contents().find("body").html(); $('#input').html(iframe_content); } else { execCommand(editor, data.command, url, null, data.button); } // Reset the text, hide the popup and set focus $text.val("https://"); hidePopups(); focus(editor); }
参考にさせていただいたページ:https://stackoverflow.com/questions/41012712/cleditor-adding-target-blank
原因と解決方法をお教えいただけますと幸いです。
どうぞよろしくお願い申し上げます。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。