android detect image click inside webview? - android

i want to detect <img click inside webview ? if so how ? i need an example plz
so far as i know i can detect <a href click inside webview by useing WebViewClient
but i need to detect <img click without using java script can i ?
this is my code :
WebView webview = ( WebView ) findViewById(R.id.wv);
WebSettings settings = webview.getSettings();
settings.setUseWideViewPort(true);
settings.setLoadsImagesAutomatically(true);
String summary = "<html><body>You scored <fieldset><legend>adfadf</legend>"
+ " <a href='http://192.168.1.100/1.jpg'><img src='http://192.168.1.100/1.jpg' /></a> </fieldset> "
+ " <b>192</b> points.</body></html>";
webview.loadData(summary, "text/html", null);

Refer this answer,
Detect click on HTML button through javascript in Android WebView
Same procedure track image click as well. If it doesn't work, create a button in HTML and place the image as background for the button, so you can track the button using answer given in the link.
Thanks.

Related

Android Dynamic content in webview

I have a dynamic content Iframe like this:
But the webview does not show the count down, only show a static image Until you re-enter the activity or reload the data manually, in this case the webview blinks every reload.
this is my code:
String html = "<iframe src="http://free.timeanddate.com/countdown/i5nxrd9z/n1440/cf100/cm0/cu4/ct0/cs0/ca0/co0/cr0/ss0/cac000/cpc000/pc009/tcfff/fn3/fs130/szw256/szh108/iso2017-04-08T15:30:00" allowTransparency="true" frameborder="0" width="256" height="108"></iframe>";
timeshower = (WebView) tournmentview.findViewById(R.id.webview1);
timeshower.loadData(html);
Thanks!
Maybe you need to set the Settings for the WebView (particularly setJavaScriptEnabled()). For example:
final WebSettings settings = timeshower.getSettings();
settings.setJavaScriptEnabled(true);

Showing iframes in android webview correctly

I want to show some html content in webView. Here is my code:
String htmlContent = "..."; // some content here
webViewContent.getSettings().setJavaScriptEnabled(true);
webViewContent.setWebViewClient(new WebViewClient());
webViewContent.setHorizontalScrollBarEnabled(false);
webViewContent.setHorizontalScrollBarEnabled(false);
webViewContent.getSettings().setSupportMultipleWindows(false);
webViewContent.getSettings().setAllowFileAccess(true);
webViewContent.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
webViewContent.setWebChromeClient(new WebChromeClient());
webViewContent.setBackgroundColor(ContextCompat.getColor(context, R.color.background_final_page));
webViewContent.loadDataWithBaseURL(null, htmlContent , "text/html", "UTF-8", null);
It shows text and images well, but when i have iframe in htmlContent , for example
<iframe allowtransparency="true" frameborder="0" scrolling="no" src="https://www.facebook.com/plugins/post.php?href=link" width="100%"></iframe>
webView shows iframe not correctly, with cropped height.When i added height="100%" to iframe code, it has no result. When i set height=600 or height=400, it works, but i cannt know in advance height size of iframe.
So, how i can to fix it?

set the text direction in WebView to RTL

how can I change text direction to the Right to Left in webview ?
This is my code
WebView web = (WebView) findViewById(R.id.web);
web.getSettings().setJavaScriptEnabled(true);
web.loadDataWithBaseURL("", myhtml, "text/html", "UTF-8", "");
I think that you need to change the dir="RTL in your HTML code.
for example:
<body dir="rtl">
<p>Some Text that will be RTL aligned</p>
</body>
WebView just allow you to view webpages but doesn't change the text direction. That only depends on the HTML markup in the web page.
If it still doesn't work, you might have issues in your HTML. You can share your code here and I can try to help you further.
Tom.
it work for me:
desc.loadDataWithBaseURL("http://www.atfonline.ir/", "<html dir=\"rtl\" lang=\"\"><body>" + outhtml + "</body></html>", "text/html", "UTF-8", null);

Open external page in InAppBrowser android 2.3 doesn't work

i have this little issue, in iOS InAppBrowser works well, but in android no way, i turn on all external page in white list, i put a console.log to see if method is called, but doesn't open here how i handling with that
link : a href="#" onclick="openInAppBrowser('my link);" class="recents">
and the method
enter code here
function openInAppBrowser(url){
console.log('click in app brownser');
console.log('page: ' + url);
window.open(encodeURI(url), '_blank', 'location=yes');
}
Any idea? In iOS works fine but in android no way, if any one could help me
Did you enable JavaScript on your webview?
http://developer.android.com/guide/webapps/webview.html
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true)

html component can't work when webview(android) reload html component again

first time when i dynamic "vamp up" strings to a well-formed html.webview it worked well, including <input = 'text', but the next time the same webview doesn't work, especially <input = 'text'
When one touches it, the keyboard appears, but one can not enter any word.
The webView setting is as follows:
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSaveFormData(false);
webView.getSettings().setSupportZoom(false);
webView.getSettings().setSavePassword(false);
webView.addJavascriptInterface(new runJavaScript(), "myjs");
webView.requestFocus();
webView.requestFocusFromTouch();
This only happens in SDK 2.0.1 & 2.1-update.
I got it. in xml file add linealayout,not webview , when make up html new webview ,new webview in java code, then add on linealayout, of couse linealayout removeallview first.

Categories

Resources