Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How To Enable & Disable JavaScript Code in WebView React Native

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.

How To Enable & Disable JavaScript Code in WebView React Native

In order to enable and disable javascript code in react native application, we need to use below props in WebView component :
  1. If we set javaScriptEnabled={true} then it will Enable the JavaScript on WebView.
  2. 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: 
How To Enable & Disable JavaScript Code in WebView React Native

This is all about enable and disable javascript code in webview componentThank 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.



This post first appeared on PHP Update Data In MySQL Database, please read the originial post: here

Share the post

How To Enable & Disable JavaScript Code in WebView React Native

×

Subscribe to Php Update Data In Mysql Database

Get updates delivered right to your inbox!

Thank you for your subscription

×