Is there a way to programmatically interact with the contents of a WebView?
For example, how could my app:
respond to an event (such as button clicked on a web page)
iterate through all the INPUT elements in a page and retrieve their contents?
Find all DIV elements with the class status and change their content?
Thanks!
You can use Javascript to make a callback to Java for anything that Javascript can detect.
You can see a demo call JS to Java here: Android Calling JavaScript functions in WebView
Related
I would like to know if there is a way to the WebView component to support a generic listener for html components. For example, the html contains an img tag with a src attribute and I would like to handle this click on java side without using specific javascript, since I don't have access to the HTML being loaded.
I noticed that Android Studio prints logs into console, so maybe there is a listener for that I can override?
I've tried using the WebView onClick handler, but it is for the component and not its content, so I wasn't able to track the html element which triggered the click to get the src value, for example.
Also, the shouldOverrideUrlLoading method from WebViewClient doesn't work either, since it is just a click and not an url change. :(
"I would like to handle this click on java side without using specific javascript, since I don't have access to the HTML being loaded."
Ah, but you do! You can use [evaluateJavaScript](https://developer.android.com/reference/android/webkit/WebView.html#evaluateJavascript(java.lang.String, android.webkit.ValueCallback)) to run some JavaScript on the page to set up the click handler you want.
I have an invisible listener above of webview and i want that when the user click on this area, the invisible listener does something and if the web has some button, it does like if the invisible listener doesn't exist.
Look into the use of Javascript interfaces within WebView. Please see this area of the Android Developers Guide. Basically, you should be able to communicate from the page to the device with the Javascript interface and let your WebView Activity know whether the button on the page is present or not.
I am working on the Google's open source Android Browser, i am working for a requirement, where i need to show some content into a new webview like a popup dialog. I shall pass some HTML data to the Webiview. I am having some JS within HTML content but the JScript is running on the main page not on the custom webview i created. Please show some way out for it.
Any JScript can be run on the webview, provided we have a script tag embedded in the HTML content rendered on custom webiew created.
Cheers
I am using webview within my app to open a page. As expected, when a dropdown in the website is clicked, a selection is opened. But i donot want this to happen. I want my webview to block a control (either dropdown, or textbox (of html) ), from being opening.
So in short, i want to block a control of a website within the webview.
How do i do this?
Any help would be appreciated.
Thanks
Are you loading a remote HTML page or do you provide an HTML string to the WebView?
If you are in the second case, you can add an (I'm talking about Javascript) event handler for the click event on the control and in this event handler you stop the propagation of the event.
This is similar How to stop event propagation with inline onclick attribute?.
This is also related event.preventDefault() vs. return false, when using jQuery.
I'm currently doing a application (project) on android. I would like to know how to create my own buttons in webview, or creating a tab bar in webview. Also, I would want to retrieve certain contents from a website (or rather, from livejournal, to be specifc), like, I do not want the buttons that are in livejournal itself, I just want certain contents, maybe like some live journal posts. Is there any way I could do this?
Thank you so much in advance!
Instead of putting tabs in the WebView you should put the WebView in Tabs. As for pulling information from LiveJournal there are two possibilites. They either have a public api that you can access to get the data you want and use that to populate your app or they don't. If they don't your only recourse would be to pull in the raw html and try to parse it. At that point you might was well just use the webpage as is.