質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
HTML5

HTML5 (Hyper Text Markup Language、バージョン 5)は、マークアップ言語であるHTMLの第5版です。

jQuery

jQueryは、JavaScriptライブラリのひとつです。 簡単な記述で、JavaScriptコードを実行できるように設計されています。 2006年1月に、ジョン・レシグが発表しました。 jQueryは独特の記述法を用いており、機能のほとんどは「$関数」や「jQueryオブジェクト」のメソッドとして定義されています。

Q&A

解決済

1回答

347閲覧

CLEditorのリンクへの「_blank」追加について

yamadadayo

総合スコア39

HTML5

HTML5 (Hyper Text Markup Language、バージョン 5)は、マークアップ言語であるHTMLの第5版です。

jQuery

jQueryは、JavaScriptライブラリのひとつです。 簡単な記述で、JavaScriptコードを実行できるように設計されています。 2006年1月に、ジョン・レシグが発表しました。 jQueryは独特の記述法を用いており、機能のほとんどは「$関数」や「jQueryオブジェクト」のメソッドとして定義されています。

0グッド

0クリップ

投稿2022/04/19 07:44

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

原因と解決方法をお教えいただけますと幸いです。
どうぞよろしくお願い申し上げます。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

下記にて解決。

if (url !== ""){   if ($("#blank").is(':checked')) {   url_cont = editor.doc.execCommand("insertHTML", false, '<a href="' + url + '" target="_blank" rel="noopener noreferrer">' + selectedText(editor) + '</a>')   execCommand(editor, data.command, url_cont, null, data.button);   } else {   execCommand(editor, data.command, url, null, data.button);    }   // Reset the text, hide the popup and set focus   $text.val("https://");   hidePopups();   focus(editor);   }

投稿2022/04/27 10:56

yamadadayo

総合スコア39

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問