Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

165
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda