[TIMOB-16376] Android: Expose Webview's configuration flags in Android for fine tuning
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Low |
Status | In Review |
Resolution | Unresolved |
Affected Version/s | Release 3.2.0 |
Fix Version/s | n/a |
Components | Android |
Labels | SupportTeam, exalture |
Reporter | Mauro Parra-Miranda |
Assignee | Unknown |
Created | 2014-02-05T00:51:55.000+0000 |
Updated | 2018-02-28T20:03:50.000+0000 |
Description
Problem Description
Currently, the Android implementation of Titanium Mobile API, will hardcode the flags for the webview behavior like:
settings.setSupportMultipleWindows(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
The user wants to be able to control those from within the JS level, in order to accomplish things like:
"I need to prevent the webview to open another window"
Any news on this ticket? I too need the ability of running android web views in one window. Would be great if it could be included in the next release.
would you all accept a pull request for this one. This is truly a trivial change. I would actually change the following lines (188- 194) to accept a value but leave these current values if none are set. The file in question is android/modules/ui/src/ti/modules/titanium/ui/widget/webview/TiUIWebView again (lines 188-194): settings.setUseWideViewPort(true); settings.setJavaScriptEnabled(true); settings.setSupportMultipleWindows(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setLoadsImagesAutomatically(true); settings.setDomStorageEnabled(true); // Required by some sites such as Twitter. This is in our iOS WebView too. @Ron I don't work for Appcelerator and I give no warranty to what I'm about to say, but if you desperately need this in a pinch then build an android module that extracts this functionality out. If someone can point me to a good way to method intercept / swizzle, then I'd hazard a module for android.
Hi Andrew, I actually always wondered what exactly a pull request is. I believe it is an outside contribution to the SDK right? If you could make it so I would gladly accept it. About creating a module for it, I thought about it, but I'm not so into java. OBJ-C no problem but I switched to Titanium to avoid having to code in java. I think all it takes is a function that accepts a webview, sets the values and returns the web view back to titanium. I'll see if I could cook that up somewhere in the next days.
Hi Andrew, Would it be possible for you to still create this pull request? I would really have no idea where to start!
supportMultipleWindows in webview is exposed. I think to disable opening new windows, one can attach a handler to onCreateWindow and return null, something like webview.onCreateWindow = function() { return null;} https://github.com/appcelerator/titanium_mobile/pull/6140
Preventing opening new windows works ok if return null. If I want to open popup contents in the same webview (like iOS does), so I do like this:
But it crashes the app. Also if I try to run the snippet from http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.WebView-property-onCreateWindow, I get a blank webview in "New page" tab and in console manymany logs like this: