This tutorial explains how to enable and disable javascript code in WebView component using react native application. This features helps the android and iOS application user to stop executing JavaScript and jQuery on their webpage loaded inside WebView in device. we are going to make a react native app with Enable and Disable JavaScript Code functionality and Stop executing JavaScript + jQuery code on their WebView Component using javaScriptEnabled={Boolean Value} prop in Android or iOS application.
In order to enable and disable javascript code in react native application, we need to use below props in WebView component :
Code snippet for WebView component :
Lets see the complete source code to enable and disable javascript code in webview component :
Screenshot:
This is all about enable and disable javascript code in webview component. Thank you for reading this article, and if you have any problem, have a another better useful solution about this article, please write message in the comment section.
In order to enable and disable javascript code in react native application, we need to use below props in WebView component :
- If we set javaScriptEnabled={true} then it will Enable the JavaScript on WebView.
- If we set javaScriptEnabled={false} then it will Disable the JavaScript on WebView.
Code snippet for WebView component :
render() { return ( <WebView style={styles.WebViewStyle} source={{uri: 'https://Google.com'}} javaScriptEnabled={false} domStorageEnabled={true} /> ); }
Lets see the complete source code to enable and disable javascript code in webview component :
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */ import React, { Component } from "react"; import { Platform, StyleSheet, View, WebView } from "react-native"; export default class App extends Component { render() { return ( <View style={styles.container}> <WebView source={{ uri: 'https://www.google.com' }} javaScriptEnabled={false} domStorageEnabled={true} /> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', }, headerText: { fontSize: 20, textAlign: "center", margin: 10, fontWeight: "bold" }, });
Screenshot:
This is all about enable and disable javascript code in webview component. Thank you for reading this article, and if you have any problem, have a another better useful solution about this article, please write message in the comment section.
No comments:
Post a Comment