Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
how to select text in webview android with JavaScript?

I am using this code to highlight text in android webview.

    public void highlight(int pageNumber) {

    dbManager = new DBManager(webView.getContext());
    dbManager.open();

    cursor = dbManager.getSelectedID(books.get(0).getmDbId());
    String quotesDb = cursor.getString(cursor.getColumnIndex("_quote"));
    String currnetPage = cursor.getString(cursor.getColumnIndex("_current_page"));

    List<String> myList = Arrays.asList(quotesDb.split("½_½"));


    webView.evaluateJavascript("function doSearch(text, backgroundColor) {\n" +
            "    if (window.find && window.getSelection) {\n" +
            "        var windowHeight = window.scrollY;\n" +
            "        document.designMode = 'on';\n" +
            "        var sel = window.getSelection();\n" +
            "        sel.collapse(document.body, 0);\n" +
            "        while (window.find(text)) {\n" +
            "            document.execCommand('HiliteColor', false, backgroundColor);\n" +
            "            sel.collapseToEnd();\n" +
            "        }\n" +
            "        document.designMode = 'off';\n" +
            "        window.scrollTo(0, windowHeight);\n" +
            "    }\n" +
            "}", null);


    Log.e("SAVE_QUOTE ", "LIST_SIZE ----> " + myList.size());

        if (pageNumber == Integer.parseInt(currnetPage)) {
                for (int j = 0; j < myList.size(); j++) {

                    webView.evaluateJavascript("doSearch('" + myList.get(j) + "', 'SkyBlue')", null);
                 //   webView.findAllAsync(myList.get(j));
                }
        }
    }

Everything works fine until I select the code with a new line (paragraph). Then I get an error and the text is not highlighted.

/chromium: [INFO:CONSOLE(1)] "Uncaught SyntaxError: Invalid or unexpected token", source: file:///data/user/0/com.mms.tts/cache/W1/index.xhtml (1)
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda