ウェブページにiframeがあります。このiframeは、私のサーバーの.txt
ファイルに送信されています(つまり、その内容を示しています)。"iframe内のすべてのテキストを選択"ボタン?
クリックすると、iFrame内のすべてのテキストがに変更されます(iFrameの外にあるボタン)を実装したいと考えています。
これは可能ですか? (たとえば、jQuery/JavaScript経由)
ウェブページにiframeがあります。このiframeは、私のサーバーの.txt
ファイルに送信されています(つまり、その内容を示しています)。"iframe内のすべてのテキストを選択"ボタン?
クリックすると、iFrame内のすべてのテキストがに変更されます(iFrameの外にあるボタン)を実装したいと考えています。
これは可能ですか? (たとえば、jQuery/JavaScript経由)
iframeには、frameまたはiframe要素によって生成されたドキュメントオブジェクトを返すcontentDocumentというDOMプロパティがあります。あなたはインラインフレームページのいずれかの方法を使用することができますiFrameName.window
HTML
<iframe id="frame" src="file.txt"></iframe>
<!-- points to the text file -->
<button id="selectText">Copy Text</button>
<!-- button to copy the text -->
JS
var selButtom = document.getElementById('selectText'); //store the button value in a variable
var frame = document.getElementById('frame'); // store iframe in variable
selButtom.addEventListener("click", function(){
var frameContent = frame.contentDocument; // get content of iframe
frameContent.execCommand('selectAll'); // execute select command
},false);
使用。
テキストを選択するには、https://code.google.com/p/rangy/を試してください。ただ単にすべてdocument.body
をiFrameName.window.document.body
に置き換えてください。
単純な代替方法:iFrameName.window.document.execCommand("selectAll")
を使用してください。
このWebページの下部にあるコードは機能しません。https://www.experts-exchange.com/questions/20699826/Selecting-all-text-within-an-iframe.html – Crickets