Disable page forwarding in Android webview
You are looking for WebClient.shouldOverrideUrlLoading
method.
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading (WebView view, String url){
//True if the host application wants to leave the current WebView and handle the url itself, otherwise return false.
return true;
}
});
How to prevent redirecting when using react-native-webview on Android
i am using react navigation. This way i do:
navigationRedirect = navState => {
const { dispatch } = this.props.navigation
const url = navState.url
if(url.includes('www.unotv.com')){
if(navState.canGoBack && navState.loading){
this.webview.goBack()
return dispatch(StackActions.push({
routeName: 'VisorWebView',
params: { url },
actions: [this.trackingForAnalytics(url)] //This function not affect the navigation
}))
}
}else{
this.webview.stopLoading()
this.webview.goBack()
Linking.openURL(url)
}
}
<WebView
ref={ref => this.webview = ref }
source={{ uri: this.state.baseURI }}
originWhitelist={["https"]}
userAgent="Mozilla/5.0 (Linux; Android 4.4.4; One Build/KTU84L.H4) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/28.0.0.20.16;]"
decelerationRate='normal'
allowsInlineMediaPlayback={true}
mediaPlaybackRequiresUserAction={false}
sharedCookiesEnabled={true}
mixedContentMode='always'
startInLoadingState={true}
containerStyle={{ marginTop: isTablet ? -60 : -50 }}
renderLoading={() => (
<ActivityIndicator
color='#29aae1'
size='large'
style={{ flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'flex-start' }}
/>
)}
onNavigationStateChange={this.redirect}
/>
When touch a link out of my domine opens the browser (Safari). If the link are on my domain, open another screen with other webview :)
Android WebView, how to handle redirects in app instead of opening a browser
Create a WebViewClient, and override the shouldOverrideUrlLoading method.
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
// do your handling codes here, which url is the requested url
// probably you need to open that url rather than redirect:
view.loadUrl(url);
return false; // then it is not handled by default action
}
});
Related Topics
Android Edittext Text Control - How to Disable Possibility to Insert Gif from Google Keyboard
How to Get Last Record from Sqlite
How to Capitalize the First Letter of Text in a Textview in an Android Application
How to Remove the Unnecessary Top Padding of the Navigation View
How to Get the Value of a Listview Item Which Is Clicked in Android
How to Delete Shared Preferences Data from App in Android
Socket.Io Client Getting Connected Disconnected Repeatedly
Constraint Layout Scroll to Bottom With Keypad Open
How to Make Buttons Align At the Middle - Android Studio
Android Navigationview: Reduce Space Between Icon and Text and 'Itembackground' Not Working
How to Painlessly Change My App Title Text Color
Adb.Exe Not Found After Installing Android Studio
Refresh/Reload/Re Instantiate a Fragment in an Android Tab System
Onclick() to Change Button Border Color Rather Changing Button Color
Remove Items from Listview With a Custom Adapter
How to Select a Video from the Gallery and Get It's Real Path