Solutions for Showing Pop-up Tabs in React Native Webview

I have a website that displays content based on user subscription status. If the subscription is active, a book is loaded; otherwise, if it's expired, a specific page is shown:

https://i.sstatic.net/HLv0B.png

To enhance user experience, I preload the content in a variable before rendering and then append it to the webview HTML. Everything loads correctly, but when I interact with certain buttons, nothing happens. I want the same functionality as on the web. How can I achieve this using React Native Webview?

https://i.sstatic.net/iPJcJ.jpg

Here is the code snippet for the webview:

<WebView 
 key={this.state.value}
 ref={webview => this.setState({WebViewRef:webview})}
 javaScriptEnabled={true}
 domStorageEnabled={true}
 scalesPageToFit={false}
 onLoadEnd={
   this.setState({
   visibleBack:false
  })
 }
 automaticallyAdjustContentInsets={false}
 source={{ html:htmlString,}} style={{height : this.state.webViewHeight, width: this.state.notSubbedHeight== 1 ? Dimensions.get('window').width-20 :Dimensions.get('window').width-40, justifyContent:'center' ,alignItems:'center',marginTop:20}}
 key={this.state.key}
 injectedJavaScript={jsBeforeLoad}
 onMessage= {this.onMessage}
 scrollEnabled={false}
/>

And here is how I retrieve the htmlString:

 getProductsummary = async (product) => {

    this.setState({ loading: true });
    const username = await AsyncStorage.getItem('username');
    if(username !== undefined){
      fetch(Config.backendAPI+`/cleanbook_mobile.php?idbook=${product.id}&username=${username}`)
      .then((response) =>{
          return response.text();
        }
      ).then((result)=>{
        let resp = result;
          if (resp == null || resp == "") {
            resp = "<div style=\"font-family:Georgia\">" + Languages.SummaryVide + "</div>";
          }
          if(resp.includes("paypal-button-container-P")){
            this.setState({notSubbedHeight:1})
          }
          this.setState({ summary: resp, loading: false });
      }).catch((error) => console.log(error));
    }else{
      this.setState({
        notSubbed: 1,
      })
    }
  };

var htmlString = `<div id="summaryDiv"> ${this.state.summary} </div>`;

Answer №1

Consider including the value for baseUrl within the source properties.

// Example

source={{ html:htmlString, baseUrl: "https://localhost"}}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Store the output of JavaScript in a PHP variable

My objective is to convert any image to base 64 and then store the converted string in a PHP variable before inserting it into my database. JavaScript Code: function uploadFile() { if (this.files && this.files[0]) { var FR= new FileReader ...

How to flip the value in v-model using VueJS

Below is the code snippet that I am working with: <input v-model="comb.inactive" type="checkbox" @click="setInactive(comb.id_base_product_combination)" > I am looking to apply the opposite value of comb.inactive to the v-model. Here are m ...

Encountering issues with styled component's flex not functioning as expected in React

I am currently working with styled-components, and I have been using "flex" for responsive design. However, I am facing some challenges in implementing it. The CSS defined within styled-components does not seem to be applying properly. The styles are not ...

Angular2: Leveraging click events to manage CSS classes on elements

I am currently developing a web app using Angular 2. I'm facing an issue where the active element should receive an extra CSS class when clicked, but adding the ":active" CSS attribute with a custom class doesn't work as expected. The ":focus" pr ...

Ways to display a variable prior to making an axios request

I have a get request that saves the result in a variable named name_student. How can I access this variable in other methods? Or how should I declare it? Here is the code snippet: getStudent(){ axios.get('https://backunizoom.herokuapp.com/student/2 ...

What is the process for removing the body of a table?

My goal is to reset the table body, which has been filled with JavaScript loaded data previously. https://i.stack.imgur.com/7774K.png ` getTableData = function (clicked_id) { if (clicked_id != '') { $.ajax({ async : f ...

Using Angular to make an API call within a JavaScript function

I am facing an issue when trying to call an API in a JavaScript function as shown below. The injected services (subService) and defined variables (formData) are not recognized in the JavaScript function, resulting in an error of undefined addSub. How can I ...

What are the compatibility considerations for npm packages with Angular 2? How can I determine which packages will be supported?

When working with Angular 2, do NPM packages need to be modified for compatibility or can any existing package work seamlessly? If there are compatibility issues, how can one determine which packages will work? For instance, let's consider importing ...

Detecting when the page is done loading in CasperJS with the help of $.ajaxStop()

During my CasperJS tests, I've relied on waitForSelector() to check if a page has finished loading, including all asynchronous AJAX requests. However, I'm interested in finding a more standard approach for waiting for page load. Is it possible to ...

Looking to organize my divs by data attributes when clicked - how can I achieve this with javascript?

I am looking to implement a dropdown sorting functionality for multiple divs based on different data attributes such as price and popularity. The specific divs are labeled as "element-1" and are contained within the "board-container". var divList = $(". ...

Learn how to incorporate draw over other app functionality in a React Native application. Ensure that users are unable to access other apps without entering a password

My vision is to develop an app that restricts the user from opening any other apps until they input the correct password. I plan on creating this feature in an android application, whether it be React Native, Flutter, or native Android I am in search of a ...

Exploring the functionality of the JavaScript Date constructor in relation to

Will using new Date('2015-01-01') provide me with the exact moment equivalent to 2015-01-01T00:00:00Z? ...

Utilizing JavaScript for loops to extract the final element from an array

I am facing an issue with the second loop within a function that goes through a JSON file. The problem is that it only returns the last item in the array. I need to figure out how to fix this because the chart object should be created on each iteration, ...

A guide to accessing REST services in AngularJS using basic authentication

I currently have a REST service up and running on my server. Using Chrome Postman, I am able to access this service with Basic Authentication. However, I now want to build a user interface in AngularJS to display the data received from the REST service. T ...

Reload the webpage locally without sending a request to the server

My goal is to refresh the browser window without needing to hit the server. I am considering using javascript for this task. Below is the code that I have, but I'm not entirely clear on what it does! <body onload="JavaScript:AutoRefresh(5000);"> ...

Issues with Displaying Components Generated from an Array in JSX

I have a task variable which has the structure as follows: [ team_id_1: { task_id_1: { description: ... }, task_id_2: { description: ... } }, team_id_2: { ... } ] When trying ...

Tips for creating clickable selections with AutoComplete JQuery in ASP.NET and C#

Currently, I am working on a project that involves implementing AutoComplete functionality in a textbox using JQuery AutoComplete. I have included the following file: jquery-ui.js The goal is to make the matched text appear in bold. For example, if I typ ...

Sort div elements based on checkbox filters

I have a set of checkboxes that I want to use for filtering purposes. <div class="filter"> <div class="checkbox"> <label><input type="checkbox" rel="canada"/>Canada</label> </div> <div class="chec ...

Troubleshooting Firebase OTP problems on Android devices with React Native

I have successfully implemented firebase OTP functionality for user authentication in my app. However, I am facing an issue where the OTP works fine on IOS but expires quickly on Android. Here are a couple of cases to illustrate: Case 1 Android Device A ...

What is the method for calculating values entered into dynamic input fields?

I am facing a slight issue with my HTML form code... Within my code, there are several input fields that are being generated dynamically. Each dynamic input field contains a numerical value which I need to use for mathematical calculations. The calculati ...