This doesn't seem to work in jqTouch or iUI. But I know it's possible because it works on my Droid when I go to deviantart.com . Anyone know how to do it?
Thanks!
Ok, I'm gonna answer my own question here. I added this bit of jQuery...
$(document).ready(function() { setTimeout(scrollTo,200,0,1) });
The timeout appears to be necessary. On my Droid, the document is not yet ready to scroll when the DOMContentLoaded event is fired.
Have you tried firing the function on window.load and on pageAnimation events?
// Hide URL bar when loading the first page
$(window).load( function() {
setTimeout(scrollTo,200,0,1);
});
// ...and on every subsequent request handled by jQTouch
$(document).delegate("body", "pageAnimationStart pageAnimationEnd", function() {
setTimeout(scrollTo,200,0,1);
});
if you are using a webkit i'm assuming that you have created an on create method, create a class below it that looks something like this
private class CallBack extends WebViewClient
{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
browser.loadUrl(url);
return true;
}
}
declare a webviewclient, and a webview when creating the parent class
WebView browser;
WebViewClient browserClient;
that should keep your app from opening an external browser.
Went through the same problem when i was starting my app project, so I hope this helps
Related
I have a web app thats working with Javascript alerts on most pages. Now I have recently created a WebView application for the same app. The app works fine, the alerts show.
I've seen solutions that suggest binding JavaScript code to Android code and then call these methods for example to show toast.
I have no doubt that this works, but now, for me, this means I'd have to re-write the code(s) that trigger these alerts.
My question is, is there a way to automatically capture all the alerts and display their contents as toasts instead?
You can use a WebChromeClient:
https://developer.android.com/reference/android/webkit/WebChromeClient
Create an instance of it, set it to your webview, and override onJsAlert.
Be sure to read the docs, to return the correct value, so it doesn't show the javascript alert also.
Thanks to Moonbloom's answer and this answer also.I managed to come with a solution that works exactly as I wanted. So for anyone who will stumble upon the same issue in the future, the snippet below is for you:
mWebView.setWebChromeClient(new WebChromeClient() {
#Override
public boolean onJsAlert(WebView view, String url, String message,
final JsResult result) {
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
result.confirm();
return true;
}
});
Where mWebView is a WebView instance.
I've been trying to inject some js into a webview in my app. Have been using
onReceivedTitle method of WebChromeClient since I want to execute the js while the page is loading.
This has been working until now. But recently, I observed that onReceivedTitle is not called we reload the webpage, similar to window.location.reload.
Firstly, I can't understand why it shouldn't be called. Or it should be and it's a bug?
Secondly, now that we know it's not called, where else can I inject by js?
Thanks.
Apparently, this is not considered an Android bug, but rather a Chrome or Chromium-based WebView bug. It should be reported to http://crbug.com/.
I'll suggest you to try a workaround with custom WebViewClient:
You'll have to use a custom WebViewClient to get this done. You will override the onPageFinished() method so when a new page finishes loading you can set the webview to the appropriate title.
Below is a sample implementation of the above:
WebView mWebView = (WebView) findViewById(R.id.mwebview);
mWebView.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url) {
ExperimentingActivity.this.setTitle(view.getTitle());
}
});
This answer here will prove to be useful:https://stackoverflow.com/a/8193479/9080948
Seems like this is a bug in chromium. I worked around this by injecting my scripts on onPageFinished method of WebviewClient.
is there a way to hide or disable the URL field in the locationbar? In my case the device is a tablet run as a kiosk browser, so only one URL is allowed.
I fixed this by changing the code in the ChildBrowser.java to
private void navigate(String url) {
InputMethodManager imm = (InputMethodManager)this.ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
if (!url.startsWith("http")) {
this.webview.loadUrl("http://" + url);
}
this.webview.loadUrl("http://www.my-only-allowed-site.example.org");
this.webview.requestFocus();
}
This works well, but is not nice. You can still see the URL. I´d like to have any of this possible solutions:
1) completely hide the URL field
2) hide the softkeyboard when clicking on the URL field
3) set the URL fonts color to black
Any idea?
thanks in advance
If you modify the source code for the plugin, you can hide the url field and close button by modifying the source code for the plugin and just comment out the following line:
toolbar.addView(back); //shows the back button
toolbar.addView(forward); //shows the forward button
//toolbar.addView(edittext); //shows the URL - comment this line out to hide the URL
toolbar.addView(close); //shows the close button
Edit: oops, I just saw from your comment that you figured this out in the same way!
I don't know anything about Phonegap but I'm assuming you're using a standard Android WebView?
If you're seeing a URL bar then it usually means that the default system browser is being invoked to handle the loading of the page. To prevent this set a WebViewClient as follows...
this.webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
The shouldOverrideUrlLoading(...) method is called by the host application to see if it should override the loading by using Activity Manager to find a suitable app (usually the stock browser app). Returning false means the WebView instance wants to handle its own URL loading and you won't see a URL bar at all.
EDIT: If that fixes it but also looses the navigation buttons then I suggest you maintain your own history collection and provide your own buttons for back/forward/exit.
I'm trying to take a screenshot of content of my WebView. I creare a bitmap and then create canvas from this bitmap, then I call method drawPage(canvas) inside onPageFinished() (that is a callback from WebChromeClient), but inside onPageFinished() webView still hasn't loaded content, so I see just black page at first, and then I see previous pages(because when I call it second time previous pages are loaded to webView). How could I deal with this problem? I can solve it using hadlers with some delay, but I think there should be better way to do this.
Thanks for help.
I don't think I understand the problem, but are you asking how to trigger an event on a WebView loading a page? Could you create a WebView client and override the onPageCompleted()?
private WebViewClient viewClient {
#Override
public boolean onPageFinished(WebView view, String url) {
//here you can run your Bitmap creating code
return true;
}
}
YourWebView.setWebViewClient(viewClient);
Is this what your looking for?
Is it possible to capture touch events over a WebView in the activity that contains it, without loosing link functionality?
Consider a WebView showing a webpage with links. If the user taps on a link I would like the WebView to handle the touch event. If the user taps somewhere else I would like the activity to handle the touch event.
How can this be done?
Yes, it is.
(I can't elaborate more on this unless you are more specific on your question.)
If i understand your question correctly it'd seem difficult to interpret whether something is a link or not in the onTouchEvent() since all it knows about is X,Y coordinates (not html). However, off the top of my head it seems you could probably use the javascript binding piece in WebView to have javascript decide if the something is a link or not and act accordingly. Again, I haven't done this before nor tested it...just thinking out loud.
When initializing your WebView, try:
mWebView.setWebViewClient(new WebViewClientOverrider());
Then create a private class:
private class WebViewClientOverrider extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//TODO handle the link
return true;
}
}
Lastly, replace the TODO handle the link line with your own code for handling the link selection.
Or you can monitor the stack trace for:
android.webkit.CallbackProxy.uiOverrideUrlLoading()
See http://www.javapractices.com/topic/TopicAction.do?Id=78 for how to determine your stack trace from a throwable (created in an overriden WebView.loadUrl() method).