iOS Question how to inject JavaScript file into webview and use js functions?

watesoft

Active Member
Licensed User
Longtime User
I want to search b4i webview and highlight the results,I search the forum and find a link:
https://www.b4x.com/android/forum/threads/webview-searching-and-highlight.49348/,I copy the javascript code inside link and make HighLight.js file.Because I don't know much about js, and a newbie to B4i, I use the below code but is not ok.

B4X:
dim JQuery as string
Private Txt_Search as  TextField
Private  WV_Search as WebView
File.Copy(File.DirAssets,"HighLight.js",File.DirTemp,"HighLight.js")
JQuery= File.Combine(File.DirTemp,"HighLight.js")
  
     WV_Search.LoadHtml($"
                                  <script src="${JQuery}"></script>
                                   "$)
     JS($"uiWebview_HighlightAllOccurencesOfString(${Txt_Search.Text}$)"$,WV_Search)

Sub JS (Script As String, WebV As WebView)
     Dim NaObj As NativeObject = WebV
     NaObj.RunMethod("stringByEvaluatingJavaScriptFromString:", Array(Script))
End Sub
 

Attachments

  • HighLight.txt
    3 KB · Views: 198
Last edited:

watesoft

Active Member
Licensed User
Longtime User
Your code looks correct. Maybe change JQuery to "file://" & File.Combine(...)

Thanks Erel, I corrected some syntax errors in HighLight.js file and change JQuery to "file://" & File.Combine(...), but still not work.:(
 
Upvote 0
Top