0

I have a html file in my assets that I load via:

webView.loadUrl(""file:///android_asset/subfolder/myhtmldoc.html",");

Inside that html file I have a accordion-table.

So when I search via:

mwebView.findAllAsync("searchterm");

it finds only the words in the open accords....

I want to open all the accords when I search. And optimal would be to close all that does not contain the word but that comes secondary.

Inside the html I have written a jQuery function:

<script type="text/javascript">
    <!-- erzeugt die akkordeonansicht zum aufklappen -->
        $(document).ready(function(){
            $("dt").click(function(){ // trigger 
                $(this).next("dd").slideToggle("fast"); // blendet beim Klick auf "dt" die nächste "dd" ein. 
                $(this).children("a").toggleClass("closed open"); // wechselt beim Klick auf "dt" die Klasse des enthaltenen a-Tags von "closed" zu "open". 
            });
        });
</script> 

Now how do I tell that html to slide down all the Toggles when I search inside it?

It should look somewhat like this:

mwebview.passCommand("$("dt").$(this).next("dd").slideToggle("fast");");
Cœur
  • 37,241
  • 25
  • 195
  • 267
NikolaiM
  • 3
  • 2
  • I also found this [question](http://stackoverflow.com/questions/4325639/android-calling-javascript-functions-in-webview/4330642#4330642): reffering to the topic!! – NikolaiM Jan 23 '15 at 12:13

1 Answers1

0

You can call any js function by using loadUrl method of WebView:

mWebView.loadUrl("javascript:myFunction();");

In your case:

mWebView.loadUrl("javascript:$('dt').$(this).next('dd').slideToggle('fast');");
nbumakov
  • 140
  • 6
  • Ahm that doesen't seem to work? :-( My Java says it doesen't know '$' – NikolaiM Jan 22 '15 at 00:13
  • I forgot to add `javascript:` in the second case. I want to say that you can perform js code by calling `webView.loadUrl("javascript:...");` – nbumakov Jan 22 '15 at 08:13
  • I mean this works: webView.loadUrl("javascript:$('dt').next('dd').slideToggle('fast');"); but this doesen't: webView.loadUrl("javascript:$("dt").next("dd").slideToggle("fast");"); some kind of obvious – NikolaiM Jan 23 '15 at 12:08
  • Yes, another way to do this is escape quotes with backslash: `webView.loadUrl("javascript:$(\"dt\").next(\"dd\").slideToggle(\"fast\");");` – nbumakov Jan 23 '15 at 12:10