pick up text selected by the user

Asked

Viewed 157 times

0

Guys I have this Javascript code below with him I’m trying to get the text selected by the user within an iframe, iframe is with designMode="on" or is it in editable mode, the problem and I’m not able to give the
Alert(string_selected text);
it me returns only the Alert with nothing.
someone can help me since I thank you.

var tag_iframe=document.querySelector('.mine-editor-de-texto');

var conteudo_tag_iframe=tag_iframe.contentDocument || tag_iframe.contentWindow.document;

var texto_selecionado=window.getSelection(conteudo_tag_iframe.body);

var string_texto_selecionado=texto_selecionado.toString();

alert(string_texto_selecionado);

2 answers

0

Guys I managed to solve my problem and I’m posting the answer, just add

frames['MINI_EDITOR_DE_TEXTO_D_NEVES']

so can get the text selected by the user within the iframe, below as my code was, I thank you for the help.


    var tag_iframe=document.querySelector('.mine-editor-de-texto');
    var conteudo_tag_iframe=tag_iframe.contentDocument || tag_iframe.contentWindow.document;
    var texto_selecionado=window.frames['MINI_EDITOR_DE_TEXTO_D_NEVES'].getSelection(conteudo_tag_iframe.body);
    var string_texto_selecionado=texto_selecionado.toString();
    alert(string_texto_selecionado);

0

Try straight through:

var string_texto_selecionado = document.querySelector('.mine-editor-de-texto').contentWindow.document.body.value;

  • Thanks Douglas Teles most unfortunately did not work the result was the same when giving Alert(string_texto_selected); I returned an empty Alert.

  • Post an example of what you’re doing using { }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.